gpt4 book ai didi

ios - xcode 4.2 iOS Tableview 使用 Storyboard

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:20:18 27 4
gpt4 key购买 nike

我使用 xcode 4.2 和 Storyboard创建了一个 iOS 选项卡式应用程序。我在上面添加了一个带有自定义单元格的 tableviewcontroller,当单击该行时,我想打开一个 tableviewcontroller,我在下面使用了以下代码

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
categoryClass *cc = [datas objectAtIndex:indexPath.row];

[tableView deselectRowAtIndexPath:indexPath animated:NO];

iSubProducts *subProducts = [[iSubProducts alloc] init];
subProducts.title = cc.categoryName;
subProducts.catID = cc.categoryID;
[[self navigationController] pushViewController:subProducts animated:YES];
[subProducts release];


}

但是当我点击该行时,出现以下错误:

* 由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“UITableView 数据源必须从 tableView:cellForRowAtIndexPath 返回一个单元格”/p>

在我的 iSubProducts tableviewcontroller 上,我有以下内容:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"myCell2";

iSubProductsCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

productSubClass *cc = [datas2 objectAtIndex:indexPath.row];
NSLog(@"Product Name: %@", cc.productName);
cell.txtProductName.text = cc.productName;
cell.txtProductDesc.text = cc.productDesc;

return cell;

}

我假设这是错误发生的地方,单元格返回一个 nil 值。当我尝试使用按钮或从按钮附加 iSubProducts tableviewcontroller 时,它一切正常,但如果它来自单击的行,则会显示此错误。

我是 iOS 开发的新手,也许从带有自定义单元格的 tableviewcontroller 打开 tableviewcontroller 时出错。我已经思考了 2 天,并在谷歌上搜索了很多,不幸的是我没有找到任何解决方案。我很确定 iSubProducts tableviewcontroller 没有错误,因为如果我尝试从按钮按下它,它就会工作。请问我需要这方面的建议,我现在对这个问题很困惑。谢谢大家。

最佳答案

注意确定这有多么有益..但就在今天,我在单击该行后从一个表格 View 移动到另一个 View 时遇到了麻烦..

我完全远离 DidSelectRowAtIndexPath。相反,我使用了 segue(这正是我的目标)。

截取的这段代码来自苹果的使用表格的 Storyboard示例。

http://developer.apple.com/library/ios/#samplecode/SimpleDrillDown/Listings/Classes_RootViewController_m.html#//apple_ref/doc/uid/DTS40007416-Classes_RootViewController_m-DontLinkElementID_10

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:@"ShowSelectedPlay"]) {
NSIndexPath *selectedRowIndex = [self.tableView indexPathForSelectedRow];
DetailViewController *detailViewController = [segue destinationViewController];
detailViewController.play = [dataController objectInListAtIndex:selectedRowIndex.row];
}
}

这一切都假设您开始在 Storyboard功能中使用 segues 并确保使用 segues 的标识符。

关于ios - xcode 4.2 iOS Tableview 使用 Storyboard,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8495268/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com