0
ChatviewControllerのテーブルビューを使用しています。 textViewに収まるサイズが必要です。 高さと幅。しかし、私は両方のパラメータでそれを作ることはできません。自動サイズのセル内のテキストビュー
この初めての設定は制限され、thisのように見えます。 この2回目の設定は制限され、thisのようになります。
これはMyProfileというコードです。
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
if messages[indexPath.row].image != nil {
tableView.rowHeight = 200
if !messages[indexPath.row].owner! {
let cell = self.chatTableView.dequeueReusableCellWithIdentifier("chatImageCell", forIndexPath: indexPath) as! ChatImageTableViewCell
cell.imageV.image = messages[indexPath.row].image
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(self.tappedAtImage(_:)))
cell.imageV.addGestureRecognizer(tapGesture)
cell.imageV.userInteractionEnabled = true
cell.transform = CGAffineTransformMakeRotation(CGFloat(M_PI))
return cell
} else {
let cell = self.chatTableView.dequeueReusableCellWithIdentifier("chatImageCellEnemy", forIndexPath: indexPath) as! ChatImageTableViewCell
cell.imageV.image = messages[indexPath.row].image
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(self.tappedAtImage(_:)))
cell.imageV.addGestureRecognizer(tapGesture)
cell.imageV.userInteractionEnabled = true
cell.transform = CGAffineTransformMakeRotation(CGFloat(M_PI))
return cell
}
} else if messages[indexPath.row].owner! {
tableView.rowHeight = UITableViewAutomaticDimension
let cell = self.chatTableView.dequeueReusableCellWithIdentifier("mymessageCell", forIndexPath: indexPath) as! MyChatTableViewCell
cell.transform = CGAffineTransformMakeRotation(CGFloat(M_PI))
cell.textView.text = messages[indexPath.row].text!
cell.textView.layer.cornerRadius = 8
cell.textView.layer.masksToBounds = true
cell.textView.textAlignment = .Right
cell.textView.textColor = .whiteColor()
cell.textView.sizeToFit()
cell.textView.layoutIfNeeded()
let unix = NSTimeInterval(messages[indexPath.row].unixDate!)
let messageDate = NSDate(timeIntervalSince1970: unix!)
cell.timeLabel.text = timeAgoSinceDate(messageDate, numericDates: true)
return cell
} else {
let cell = self.chatTableView.dequeueReusableCellWithIdentifier("messageCell", forIndexPath: indexPath) as! ChatTableViewCell
tableView.rowHeight = UITableViewAutomaticDimension
cell.transform = CGAffineTransformMakeRotation(CGFloat(M_PI))
cell.textView.text = messages[indexPath.row].text!
cell.textView.layer.cornerRadius = 8
cell.textView.layer.masksToBounds = true
cell.textView.textColor = .blackColor()
cell.textView.sizeToFit()
cell.textView.layoutIfNeeded()
let unix = NSTimeInterval(messages[indexPath.row].unixDate!)
let messageDate = NSDate(timeIntervalSince1970: unix!)
cell.timeLabel.text = timeAgoSinceDate(messageDate, numericDates: true)
return cell
}
}
ありがとうございます!
答えに感謝しますが、私が間違ったことを正確に理解できませんでした。コードを教えてくれませんか? – coolfrut
実際にあなたが直面している問題は、あなたの質問に追加した画像、画像の右側に出力が表示されますが、正しいと思われますが、あなたのコードははるかに修正する必要があります。 。情報のために 'messages []'は何ですか? –
messagesはstruct Messageの配列なので、メッセージは structメッセージ{ var text:String? var unixDate:String? var status:Int? var所有者:Bool? var id:文字列? var image:UIImage? } – coolfrut