这是我第一次在这里提出问题,但我不得不说这个网站在过去的几个月里对我有很大的帮助(iphone-dev-明智的),我感谢你。UITableView:在空白部分添加节页脚视图时崩溃
但是,我没有找到任何解决方案,我有这个问题: 我有一个UITableView与2节,并没有行时,应用程序第一次启动。用户可以按照自己的意愿稍后填写章节(内容与此无关)。当用行填充时,UITableView看起来很不错,但是当没有空时,看起来非常难看(2个标题部分粘在一起,中间没有空白)。这就是为什么我想在没有行时添加一个很好的“无行”视图。
我用viewForFooterInSection:
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
if(section == 0)
{
if([firstSectionArray count] == 0)
return 44;
else
return 0;
}
return 0;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
if(section == 0)
{
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(200, 10, 50, 44)];
label.backgroundColor = [UIColor clearColor];
label.textColor = [UIColor colorWithWhite:0.6 alpha:1.0];
label.textAlignment = UITextAlignmentCenter;
label.lineBreakMode = UILineBreakModeWordWrap;
label.numberOfLines = 0;
label.text = @"No row";
return [label autorelease];
}
return nil;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if(section == 0)
{
return [firstSectionArray count];
}
return [secondSectionArray count];
}
这个伟大的工程:只有当在第0 无行,但出现的页脚视图我的应用程序崩溃,当我进入编辑模式,并删除部分最后一行0:
断言故障 - [UIViewAnimation initWithView:indexPath:endRect:endAlpha:startFraction:endFraction:曲线:animateFromCurrentPosition:shouldDeleteAfterAnimation:编辑:] 终止应用程序由于未捕获的异常“NSInterna lInconsistencyException”,理由是:‘细胞停止动画分数必须大于开始部分’
此当有节0几行不会发生这只有当只有一排左边发生。
下面是编辑模式代码:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
// If row is deleted, remove it from the list.
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Find the book at the deleted row, and remove from application delegate's array.
if(indexPath.section == 0)
{ [firstSectionArray removeObjectAtIndex:indexPath.row]; }
else
{ [secondSectionArray removeObjectAtIndex:indexPath.row]; }
// Animate the deletion from the table.
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
withRowAnimation:UITableViewRowAnimationBottom];
[tableView reloadData];
}
}
没有人有任何想法,为什么发生这种情况? 谢谢
你是我的英雄!将“无数据”单元缩小2个像素使其全部工作!非常感谢! (和FYI,我已经想到了第二个解决方案,但无法使其工作) 但我仍然有一个小问题:tableview的背景是白色,现在当第0部分没有行时,我更喜欢它。它充满了空单元格(请参阅http://yfrog.com/izuitableviewproblemp)。任何提示? 再次谢谢大卫,你让我的一天! – nmondollot 2009-12-12 17:33:46
那里没有很棒的想法,也许值得一个单独的问题。 – 2009-12-12 18:00:04
好的,这就是我所做的。谢谢 – nmondollot 2009-12-12 18:22:52