如何在UIViewController打开页面后自动滚动到底部?
当前,当我打开页面时它滚动到了顶部.. 但是我需要它在底部,因为那里有最新的消息。
这是表格视图的Swift代码:
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.dataArr.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "messages") as! UITableViewCell
cell.selectionStyle = .none
let message = cell.viewWithTag(100) as! UILabel
let name = cell.viewWithTag(101) as! UILabel
let data = self.dataArr[indexPath.row] as! [String:AnyObject]
message.text = " " + String(describing: data["message"]!) + " "
name.text = String(describing: data["name"]!)
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
var mapStr = ""
let data = self.dataArr[indexPath.row] as! [String:AnyObject]
let message = String(describing: data["message"]!)
let array = message.components(separatedBy: "\n") as! [String]
let arrayLoc = message.components(separatedBy: "Location: ") as! [String]
if arrayLoc.count > 0 {
mapStr = arrayLoc[1]
}
print(mapStr)
if mapStr.count > 0 {
self.open(scheme: mapStr)
}
}
}