Soy nueva programando para iOS por lo que no se como resolver este problema, tengo una vista donde tengo 2 tableview uno donde selecciona que chat desea abrir y el otro table es donde se muestran los mensajes. Ahora tengo 3 problemas
A la hora de seleccionar el chat no se muestran mis mensajes automáticamente (Refresh) si no hasta seleccionar el tableview chat
A la hora de enviar un mensaje no muestra el globito gris e igual intente refrescarlo y ni así solo me elimina los mensajes
Que cada vez que se envie un mensaje o te muestre el chat se muestre el ultimo mensaje
Este es mi código del table View
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
var cell:UITableViewCell?
if tableView == self.tableView2 {
let tu = ((identificador[indexPath.row])as NSString).integerValue
if tu == 2{
let cell = tableView.dequeueReusableCell(withIdentifier: "Messages", for: indexPath) as! ChatTableViewCell
cell.emisor.isHidden = true
cell.receptortxt.text = self.chats[indexPath.row]
return cell
}
else if tu == 1{
let cell = tableView.dequeueReusableCell(withIdentifier: "Messages", for: indexPath) as! ChatTableViewCell
cell.receptor.isHidden = true
cell.emisortxt.text = self.chats[indexPath.row]
return cell
}
}
if tableView == self.tableView {
cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
cell?.textLabel?.text=separated[indexPath.row]
}
return cell!
}
Este es el código al seleccionar chat
func peticionhttp()
{
/// Codigo que manda a traer cual chat
self.refresh()
self.boton.setTitle("\(self.separated[0])", for: .normal)
}
}
task.resume()
}
func refresh(){
print("refreshed" , tu2)
self.tableView2.reloadData()
self.tableView2.separatorStyle = .none
}
Código al enviar mensaje
@IBAction func onClicEnviar(_ sender: Any) {
// dismissKeyboard()
peticionhttpcuatro()
refresher = UIRefreshControl()
refresher.attributedTitle = NSAttributedString(string: "Pulsa para refrescar")
refresher.addTarget(self, action: #selector(ChatIndividual.refrescar), for: UIControlEvents.valueChanged)
tableView2.addSubview(refresher)
}
@objc func refrescar () {
chats.append(textfield.text!)
identificador += ["1"]
tableView2.reloadData()
refresher.endRefreshing()
print(chats,identificador,"Heeeeeeeeeeeeeeeeeeey ")
}
P.d: No estoy utilizando Firebase