【发布时间】:2018-08-14 09:38:47
【问题描述】:
我正在从服务器获取大约 30 个问题的数据,并且想在包含文本框、标签和下一步按钮的 tableviewcell 中一次只显示一个问题。单击下一个按钮后,它应该显示另一个带有下一个问题的单元格。怎么可能
任何想法/建议都会有所帮助
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "MyCell", for: indexPath as IndexPath)
let dic=self.arrQues[Index] as! NSDictionary
lblQues.frame = CGRect(x: 20, y: 10, width: 280, height: height)
lblQues.textAlignment = .left
lblQues.text = dic["Question"] as? String
lblQues.font = UIFont(name:"ArialMT", size: 20.0)
lblQues.numberOfLines = 0
lblQues.lineBreakMode = .byWordWrapping
lblQues.textColor = UIColor.black
cell.contentView.addSubview(lblQues)
btnnext.setTitle("Next", for: [])
btnnext.setTitleColor(UIColor.white,for: [])
btnnext.backgroundColor = UIColor(red: 0/255, green: 124/255, blue: 223/255, alpha:1)
btnnext.layer.cornerRadius = 5
btnnext.frame = CGRect(x: lblQues.frame.origin.x, y:txtQuestion.frame.origin.y+txtQuestion.frame.size.height+30, width: 200, height: 40)
btnnext.addTarget(self, action: #selector(buttonNextClicked), for: .touchUpInside)
cell.contentView.addSubview(btnnext)
return cell
}
@objc func buttonNextClicked(sender: UIButton!) {
Index=Index+1;
// display next question data
}
【问题讨论】:
-
CollectionView 分页可以满足您的要求。
-
你能提供设计的截图吗?
-
您可以使用全宽容器视图和
UIButton点击您需要scrollToRow查看下一个问题的水平集合视图 -
为什么这里需要表格视图?你可以展示一下 ui 设计吗?
-
当按钮被点击时,使用 UITableView.numberOfRows 和 UITableView.cellForRow 浏览 tableView。对于每个单元格,除了您需要的单元格之外,将 contentView.isHidden 设置为 true。
标签: ios iphone swift uitableview xcode8