ios - 我有一个 uitableview,它有动态单元格,当我滚动它时,在 uitextview 中的某些单元格中,简单文本被检测为链接

标签 ios swift uitableview uitextview

www.facebook.com 是一个链接,但 heyday 只是一个文本,它显示为链接

我有一个 UITableView,它具有动态单元格,当我滚动它然后在某些单元格中时,UITextView 中的简单文本被检测为链接。

请参阅下面的屏幕截图。

enter image description here

最佳答案

{

if person.valueForKey("type") as? String == Content_Type.CONTENT_TYPE_AUDIO
            {
                let cellIdentifier = "senderAudio"
                let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as! SenderAudioTableViewCell
                cellHeight[indexPath.row] = "Audio"
                cell.audioContent.layer.cornerRadius = 10
                if NSData(contentsOfFile: (person.valueForKey("lurl") as? String)!) != nil
                {
                    cell.senderAudioButton.setImage(UIImage(named: "ic_play_circle_outline_2x.png"), forState: UIControlState.Normal)
                    cell.senderAudioButton.setImage(UIImage(named: "ic_stop_2x.png"), forState: UIControlState.Selected)

                    cell.senderAudioButton.addTarget(self, action: "buttonAction:", forControlEvents: UIControlEvents.TouchUpInside)
                    self.audioDict[indexPath.row] = (person.valueForKey("lurl") as? String)!
                    cell.senderAudioButton.tag = indexPath.row
                }
                else
                {
                    SocketClient.updateLurlForCorruptImage((person.valueForKey("lurl") as? String)!, mid: (person.valueForKey("id") as? String)!)

                }
                var messagetime = (person.valueForKey("tim") as? String)!
                messagetime = messagetime.stringByReplacingOccurrencesOfString("\\Optional[(](\\w+)[)]", withString: "$1", options: NSStringCompareOptions.RegularExpressionSearch, range: Range<String.Index> (start: messagetime.startIndex, end: messagetime.endIndex))
                let timeinterval = Double(messagetime)
                let date = NSDate(timeIntervalSince1970: timeinterval!/1000)
                cell.audioSentTimeLabel.text = SocketClient.getLocalTimeWithAMPM(date)
                cell.audioSentTimeLabel.textColor = UIColor(red: 171/255, green: 172/255, blue: 172/255, alpha: 1.0)

                if person.valueForKey("mst") as? String == "1"
                {
                    cell.audioSentStatus.image = UIImage(named: "mesagesingletick-01.png")
                }
                else
                {
                    cell.audioSentStatus.image = UIImage(named: "mesageloading-01.png")
                }

                cell.setNeedsUpdateConstraints()
                cell.updateConstraintsIfNeeded()

                return cell
            }

            else
            {
                let cellIdentifier = "senderMessage"
                let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as! SenderMessageTableViewCell

                cell.messageContentView.layer.cornerRadius = 10
                var messagetime = (person.valueForKey("tim") as? String)!
                messagetime = messagetime.stringByReplacingOccurrencesOfString("\\Optional[(](\\w+)[)]", withString: "$1", options: NSStringCompareOptions.RegularExpressionSearch, range: Range<String.Index> (start: messagetime.startIndex, end: messagetime.endIndex))
                let timeinterval = Double(messagetime)
                let date = NSDate(timeIntervalSince1970: timeinterval!/1000)
                cell.timeLabel.text = SocketClient.getLocalTimeWithAMPM(date)
                cell.timeLabel.textColor = UIColor(red: 171/255, green: 172/255, blue: 172/255, alpha: 1.0)

                if person.valueForKey("mst") as? String == "1"
                {
                    cell.messageSendingStatus.image = UIImage(named: "mesagesingletick-01.png")
                }
                else
                {
                    cell.messageSendingStatus.image = UIImage(named: "mesageloading-01.png")
                }

                cell.messageTextview.text = person.valueForKey("body") as? String
                cell.messageTextview.sizeToFit()
                cellHeight[indexPath.row] = cell.messageTextview.frame.height
                cell.setNeedsUpdateConstraints()
                cell.updateConstraintsIfNeeded()

                return cell

            }  

}

关于ios - 我有一个 uitableview,它有动态单元格,当我滚动它时,在 uitextview 中的某些单元格中,简单文本被检测为链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35812836/

相关文章:

iOS : UIImage created by UIBezierPath not smooth

ios - iframe 在 ios 上滚动固定 div 不起作用

ios - 如何在 Swift 中创建像指南针一样的 'sliding view' ?

ios - SQLite3 并不总是正常工作(无法准备或执行查询)

swift - 升级到 Swift 3.0 后,从左到右的动画不起作用

ios - Fabric API key 无效

cocoa-touch - 如何知道键盘何时隐藏文本字段?

ios - 我如何在 iOS 的 Swift 中将 Instagram 设计为在提要页面上切换以在 GridView 和 ListView 之间切换?

iphone - 自定义 UITableViewCell 出错

ios - Instagram 风格的相机转换