所以我在使用套接字 io 中创建了一个聊天页面,我有 2 个用于传入和传出消息的标签。
我有一个名为 ChatText 的变量,它将像这样存储内容:
[[“嗨,你好吗?”,“0”],[“我很好,你呢?”,“1”]]
其中 0 = 已发送,1 = 已接收
所以我可以知道哪个是发送和接收的消息,并将它们设置为标签并设置它们的样式
我不知道这是否是正确的方法,我在互联网上搜索找不到太多信息,所以我就这样做了,请告诉我是否错误或告诉我如何解决这个问题。
这是我到目前为止的代码,我认为问题一定是:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
let cell = tableView.dequeueReusableCellWithIdentifier("chatCell", forIndexPath: indexPath) as? TableChatCell
cell!.selectionStyle = UITableViewCellSelectionStyle.None
let ChatTextFixed = self.ChatText[indexPath.row] as NSArray
if ChatTextFixed.count > 0 {
if ChatTextFixed[1] as! Int == 0 {
cell!.ChatLableS.text = ChatTextFixed[0] as? String
cell!.RView.hidden = true
}
if ChatTextFixed[1] as! Int == 1 {
cell!.ChatLableR.text = ChatTextFixed[0] as? String
cell!.SView.hidden = true
}
print(ChatTextFixed)
}
cell!.ChatLableS.textColor = UIColor.whiteColor()
cell!.ChatLableR.textColor = UIColor.blackColor()
return cell!
}
注意:如果我删除这些 If 条件:
if ChatTextFixed[1] as! Int == 0 {}
if ChatTextFixed[1] as! Int == ! {}
并将文本设置为 1 标签,它的工作原理如下:
cell!.ChatLableS.text = ChatTextFixed[0] as? String
cell!.RView.hidden = true
更新
问题是因为
cell!.RView.hidden = true
cell!.SView.hidden = true
但我怎样才能隐藏另一个标签并只显示一个!