ios - 带有导航 Controller 的 Xcode TableView Controller 不显示表格单元格,但正在处理单元格中的数据

标签 ios swift xcode uitableview uinavigationcontroller

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

就像现在一样,当我单击加号按钮时,它会将我带到正确的页面,并且导航栏按钮在该页面上工作。当我单击“完成”时,我在 Storyboard中输入的文本字段中的文本将添加到列表中,因此我知道它在某个地方。我设置了自动布局,所以这不应该是问题。看起来好像有东西覆盖了表格单元格(全部为深灰色),但我不知道它是什么。请参阅下面的图片以进行说明:

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

第二个 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/

相关文章:

ios - 限制 UIDate View 滚动到旧日期?

ios - 如何确保生成的随机数不等于下一个生成的数?

ios - 计算 DragGesture 的速度

css - 我们如何在 ios 9 的 uiwebview 中禁用放大镜 - Swift

Xcode 不支持 iOS : Could not locate device support files

ios - UITableViewDataSource 和 UIViewController 之间的通信

iphone - 标题和栏按钮未显示在导航栏中

xcode - 当信标在范围内时如何使用 PerformSegueWithIdentifier

javascript - fullpage.js - 在不在 fullpage.js 包装器中的 div 内滚动在 IOS 上是不可能的

swift - 如何返回一个数组?