带有Nav Controller的Xcode表视图控制器不显示表格单元格,而是处理来自单元格的数据

时间:2016-09-11 16:26:30

标签: ios swift xcode uitableview uinavigationcontroller

我正在使用表视图和导航控制器为列表设置基本CRUD操作。当我在我的初始表视图中单击加号按钮时,它应该使用segue以模态方式呈现下一个表视图,我可以在表单元格中的文本字段中将项添加到列表中。

就像现在一样,当我点击加号按钮时,它会转到右侧页面,导航按钮会在该页面上运行。当我点击完成后,我在textField中输入的文本被添加到列表中,所以我知道它在某处。我有自动布局设置,所以不应该是问题。看起来有些东西覆盖着桌子上的细胞(所有颜色都是深灰色),但我无法弄清楚它是什么。请参阅下面的图片以获得澄清:

this image shows the storyboards, the last board is the one I having trouble with

this images shows the progression of the app as it is now, the middle frame should be showing the text field

第二种观点的代码:

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 CancelButtonDelegate: class {
func cancelButtonPressedFrom(controller: UIViewController)

}

protocol MissionDetailsViewControllerDelegate: class {
func missionDetailsViewController(controller: MissionDetailsTableViewController, didFinishAddingMission mission: String)

}

1 个答案:

答案 0 :(得分:0)

我仍然不确定发生了什么,但这对我有用:

我在第二个视图控制器中取消注释了这个默认的代码行,并看到我的表格单元格出现了。我推荐了它,它仍然有效。

self.navigationItem.rightBarButtonItem = self.editButtonItem()