我的表有两个部分,在第一部分我没有总是有元素;
我已将此条件if([tableView numberOfRowsInSection:section]<=0) return 0;
置于我的viewForHeaderInSection
方法中但我的应用程序仍然需要EXC_BAD_ACCESS
这是我自定义的headerView:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
if([myTableView numberOfRowsInSection:section]<=0) return 0;
NSString *headerTitle = [titlesArray objectAtIndex:section];
UIView *customView = [ [ [UIView alloc] initWithFrame: CGRectMake(0.0, -5.0, 320.0, 25.0) ] autorelease ];
[customView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"myTableBackground.png"]]];
UIView *clearView = [ [ [ UIView alloc ] initWithFrame: CGRectMake(0.0, -5.0, 320.0, 25.0) ] autorelease ];
[clearView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:nil]]];
UIButton *button = [ [ [ UIButton alloc ] initWithFrame: CGRectMake(-9.0, 5.0, 320, 27.0) ] autorelease ];
button.tag = section;
[button setImage:[UIImage imageNamed:@"header_section_background.png" ] forState: UIControlStateNormal ];
button.highlighted = NO;
button.adjustsImageWhenHighlighted = NO;
UILabel *label = [ [ UILabel alloc ] initWithFrame:CGRectMake(15.0, 5.0, 45, 22.0) ];
label.alpha = 1.0;
label.backgroundColor = [UIColor clearColor];
label.text = title;
label.textAlignment = UITextAlignmentRight;
[customView addSubview: button ];
[customView addSubview:label ];
[customView sendSubviewToBack:button];
return customView;
}
有任何线索如何解决这个问题?
答案 0 :(得分:1)
您应该返回nil
而不是0
。
您可能/应该使用tableView
参数而不是myTableView
变量。