我正在努力使用 TableView 和导航 Controller 为列表设置基本的 CRUD 操作。当我单击初始 TableView 中的加号按钮时,它应该使用 segue 以模态方式呈现下一个 TableView ,我可以在其中将项目添加到表单元格中的文本字段中的列表中。
就像现在一样,当我单击加号按钮时,它会将我带到正确的页面,并且导航栏按钮在该页面上工作。当我单击“完成”时,我在 Storyboard中输入的文本字段中的文本将添加到列表中,因此我知道它在某个地方。我设置了自动布局,所以这不应该是问题。看起来好像有东西覆盖了表格单元格(全部为深灰色),但我不知道它是什么。请参阅下面的图片以进行说明:
this image shows the storyboards, the last board is the one I having trouble with
第二个 View 的代码:
class MissionDetailsTableViewController: UITableViewController {
@IBAction func cancelBarButtonPressed(sender: UIBarButtonItem) {
cancelButtonDelegate?.cancelButtonPressedFrom(self)
}
@IBAction func doneBarButtonPressed(sender: UIBarButtonItem) {
delegate?.missionDetailsViewController(self, didFinishAddingMission: newMissionTextField.text!)
}
@IBOutlet weak var newMissionTextField: UITextField!
weak var cancelButtonDelegate: CancelButtonDelegate?
weak var delegate: MissionDetailsViewControllerDelegate?
override func viewDidLoad() {
super.viewDidLoad()
// Uncomment the following line to preserve selection between presentations
// self.clearsSelectionOnViewWillAppear = false
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
第二个文件中的协议(protocol):
protocol CancelButtonDelegate: class {
func cancelButtonPressedFrom(controller: UIViewController)
}
protocol MissionDetailsViewControllerDelegate: class {
func missionDetailsViewController(controller: MissionDetailsTableViewController, didFinishAddingMission mission: String)
}
最佳答案
我仍然不确定发生了什么,但这对我有用:
我在第二个 View Controller 中取消注释了这行默认代码,并看到我的表格单元格出现了。我推荐了它,它仍然有效。
self.navigationItem.rightBarButtonItem = self.editButtonItem()
关于ios - 带有导航 Controller 的 Xcode TableView Controller 不显示表格单元格,但正在处理单元格中的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39438217/