iOS Swift - UITableView didselectrowatindexpath 崩溃

标签 ios uitableview swift didselectrowatindexpath

首先,让我说这是一个菜鸟问题,所以请耐心等待 :D。我在导航控件中嵌入了一个表格 View ,它是我的主视图。有一个“添加”按钮,我可以在其中添加“东西”,然后当它被触发时,它会在表格 View 上显示添加的项目,并使用下面的代码切换回主视图 Controller

@IBAction func buttonAddPost_Click(sender: UIButton) {
postMgr.addPost(titleBox.text, description: descriptionBox.text, postDate: date)
self.navigationController.popToRootViewControllerAnimated(true)
}

上面的代码再次将我带回主 TableView Controller 。

但是,当我单击一个单元格以查看更详细的 View 时,应用程序崩溃了。这是代码

override func tableView(tableView: UITableView!, didSelectRowAtIndexPath indexPath: NSIndexPath!) {
let listingPage = self.storyboard.instantiateViewControllerIdentifier("listingPage") as PostListingTableViewController
self.navigationController.pushViewController(listingPage, animated: true)
}

“listingPage”是我要访问的新 View Controller 的 Storyboard ID。我在其他地方多次使用上述技术并且工作得很好,但我不确定这里出了什么问题。

我得到的错误: 线程 1 0 swift_dynamicCast 并突出显示 0x1d7150:pushl %ebp 线程 1:EXC_BREAKPOINT(代码=EXC_I386_BPT) 1个 2 Exchange.PoSTListTableViewController ([app name].[class name]) 它突出显示了 didselectrowatindexpath . . .

请帮忙...

公里数

最佳答案

异常会告诉您问题所在 - 您将 View Controller 转换为 as PostListingTableViewController 但返回的对象类型是 PoSTListTableViewController 因此转换会生成异常。

您需要确定正确的类名是什么,并更新您的 Storyboard或您的 didSelectRowAtIndexPath 以便它们保持一致 - PoSTList 或 PostListing。

关于iOS Swift - UITableView didselectrowatindexpath 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24273123/

相关文章:

ios - Calendar.Component 中的季度组件有什么作用? ( swift )

ios - 如何在TableView下面添加View?

ios - @Observable 没有完全按要求工作

swift - 用户录制音频时创建语音频率图?

ios - UIApplicationBackgroundFetchIntervalMinimum 的实际值是多少?

jquery - ajax 请求中的 html() 在 iOS 设备上不起作用

ios - 当用户滚动到最后一个 tableViewCell 时执行操作

ios - 设置cell.textLabel.textColor导致IOS其他section颜色不一致

ios - Swift:单击 UICollectionView 的单元格并打开 AlertViewController

android - 如何在Android中制作类似于滚动壁纸的背景图像?