【发布时间】:2012-04-10 07:06:35
【问题描述】:
我制作了一个演示空应用程序并添加了一个带有视图的导航控制器
UINavigationController *navBar = [[UINavigationController alloc]initWithRootViewController:objFirstViewControllerViewController];
[self.window addSubview:navBar.view];
之后我像这样在第一个视图控制器上添加一个表格视图。
UITableView* demotableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 320, 400) style:UITableViewStylePlain];
demotableView.delegate = self;
demotableView.dataSource = self;
[self.view addSubview:demotableView];
表格视图的委托功能和行功能的主单元格像这样
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell.textLabel.text = @"Hello this is sample text";
cell.textLabel.minimumFontSize = 12;
cell.textLabel.adjustsFontSizeToFitWidth = TRUE;
cell.textLabel.font = [UIFont fontWithName:@"Copperplate" size:18];
return cell;
}
但是当我在我的表格上滚动或单击任何单元格以进入下一个视图时,它只会崩溃并分别在单击和滚动时出现这两个错误。
[__NSCFArray tableView:didSelectRowAtIndexPath:]
[__NSCFDictionary tableView:cellForRowAtIndexPath:]
我不明白这段代码有什么问题,它一直在与以前的操作系统正常工作
任何机构可以帮忙吗?
这里是选择行的代码
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
Second *anotherViewController = [[Second alloc] initWithNibName:nil bundle:nil];
[self.navigationController pushViewController:anotherViewController animated:YES];
}
并且没有这一行
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 15;
}
【问题讨论】:
-
可以添加 didselectrow 和 numberofrows 方法的代码吗?
-
@RIP 我已添加代码,请检查
-
您的错误表明 tableview:cellForRowAtIndexPath: 和 tableView:didSelectRowAtIndexPath: 正在发送到 NSArray 和/或 NSDictionary。您确定将实现 UITableViewDataSourceDelegate 协议的对象作为 demotableView.dataSource 传递吗?
-
其实我只是用这个 demotableView.delegate = self; demotableView.dataSource = self;在 .h 中我声明我想使用表格视图的委托和数据源方法,除此之外,我不对单元格进行任何操作
-
@Ballu 似乎与某些变量的发布有关,请您仔细检查您在代码中编写的发布声明。
标签: iphone objective-c uitableview ios5