Adn*_*hry 6 iphone ios7 xcode5
我的故事板有问题.它工作正常但是当我尝试更改UITableView的内容属性时导致以下错误
断言失败 - [UITableView dequeueReusableCellWithIdentifier:forIndexPath:],/ SourceCache/UIKit/UIKit-2903.23/UITableView.m由于未捕获的异常'NSInternalInconsistencyException'而终止应用程序,原因:'无法使用标识符Cell将单元格出列 - 必须注册一个笔尖或标识符的类或连接故事板中的原型单元格'
我想用静态单元格设计一个分组的tableview.Thanks提前
码
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 3;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
return cell;
}
Run Code Online (Sandbox Code Playgroud)
小智 7
如果你使用静态单元格,只需注释所有UITableViewDatasourceDelegate方法.所以请注释以下代码:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 3;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
return cell;
}
Run Code Online (Sandbox Code Playgroud)
希望这会对你有所帮助!
小智 7
而不是使用:
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
Run Code Online (Sandbox Code Playgroud)
// - >这在使用原型单元格(例如)Dynamic TableView时使用
使用:
UITableViewCell *cell = [super tableView:tableView
cellForRowAtIndexPath:indexPath];
Run Code Online (Sandbox Code Playgroud)
// - >由于您选择了Static TableCells,因此您无需重复使用,而是使用您在nib中创建的单元格
使用故事板时,必须在故事板中注册表格视图单元格。这意味着必须将单元格添加到表中,并且必须设置其标识符。该标识符应在代码中使用cellForRowAtIndexpath
编辑
如果是静态单元格,则需要在笔尖中创建每个点状单元格,并通过代码或笔尖填充内容
读这个
| 归档时间: |
|
| 查看次数: |
11382 次 |
| 最近记录: |