使用带有以下代码的自定义UITableViewCell实现UITableView
@interface ProfileSaveViewController : UITableViewController
{
UITableViewCell *cell0;
UITableViewCell *cell1;
UITableViewCell *cell2;
UILabel *cell2Label;
}
@property (nonatomic, retain) IBOutlet UITableViewCell *cell0;
@property (nonatomic, retain) IBOutlet UITableViewCell *cell1;
@property (nonatomic, retain) IBOutlet UITableViewCell *cell2;
@property (nonatomic, retain) IBOutlet UILabel *cell2Label;
@end
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath*)indexPath
{
if([indexPath row] == 0) return cell0;
if([indexPath row] == 1) return cell1;
if([indexPath row] == 2) return cell2;
return nil;
}
Run Code Online (Sandbox Code Playgroud)
运行应用程序时出现以下消息.
*断言失败 - [UITableView _createPreparedCellForGlobalRow:withIndexPath:],/ SourceCache/UIKit_Sim/UIKit-1912.3/UITableView.m:6072 2012-03-01 11:11:31.984 TestSplitView [765:f803]*由于未捕获的异常而终止应用'NSInternalInconsistencyException',原因:'UITableView dataSource必须从tableView返回一个单元:cellForRowAtIndexPath:'
你被要求一个单元格并返回nil(或者可能是其他不是a的东西UITableViewCell).就是这么简单.
我看到两种可能性:
您将返回一个大于3的数字tableView:numberOfRowsInSection:.别.
您的一个或多个cell#插座没有连接到您的笔尖,或者没有连接到UITableViewCell(或子类).正确地连接它们.
| 归档时间: |
|
| 查看次数: |
12681 次 |
| 最近记录: |