坏访问错误的UITableView
问题描述:
下面的部分是我的code.Which我用它来显示对表的部分内容,并重新加载部分中单击坏访问错误的UITableView
-(UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
NSArray *arr=[[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];
CustomCell *cellHeader=[arr objectAtIndex:0];
UIButton *button = [[UIButton alloc] initWithFrame: CGRectMake(0.0, 0.0, 320.0, 80.0)];
button.alpha = 0.7;
button.tag=section;
/* Prepare target-action */
[button addTarget: self action: @selector(handleTap:) forControlEvents: UIControlEventTouchUpInside];
[cellHeader.contentView addSubview: button];
objISLMenu= [self.dataArray objectAtIndex:section];
NSString *titleStr= objISLMenu.displayName;
cellHeader.titleLabel.text=titleStr;
if(section ==selectedSection){
//bg as red
[cellHeader.contentView setBackgroundColor:[UIColor redColor]];
//text as white
[cellHeader.titleLabel setTextColor:[UIColor greenColor]];
}
else{
//bg as white
[cellHeader.contentView setBackgroundColor:[UIColor redColor]];
//text as white
[cellHeader.titleLabel setTextColor:[UIColor greenColor]];
}
return cellHeader.contentView;
}
-(void)handleTap:(UIButton*)sender
{
NSLog(@"%ld",(long)sender.tag);
if(selectedSection==sender.tag){
//clicked is same as expanded
selectedSection=-1;
[self.tableview reloadSections:[NSIndexSet indexSetWithIndex:sender.tag] withRowAnimation:UITableViewRowAnimationNone];
}
else{
NSLog(@"%ld",(long)sender.tag);
long removesectionid=selectedSection;
selectedSection=sender.tag;
[self.tableview reloadSections:[NSIndexSet indexSetWithIndex:sender.tag] withRowAnimation:UITableViewRowAnimationNone];
if(removesectionid!=-1){
[self.tableview reloadSections:[NSIndexSet indexSetWithIndex:removesectionid] withRowAnimation:UITableViewRowAnimationNone];
}
if([tableview numberOfRowsInSection:sender.tag] ==0)
{
[self updateViewControllerWithIndex:sender.tag];
}
}
}
我用这代码显示关于按钮点击部分重新加载部分数据的数据。长按部分给我一个错误的访问错误。
答
而不是增加对内容视图子视图上添加视图
问题寻求帮助调试(“为什么不是这个代码的工作?”)必须包括所期望的行为,一个具体问题或**错误**和在问题本身中重现它所需的最短代码。 – peko 2014-09-19 09:45:05
同意。你是否尝试过在未捕获的异常处理程序上设置断点等明显的事情。我怀疑您的问题是您的部分重新加载代码已损坏。 – 2014-09-19 09:48:29
对不起,但它在单击时工作正常 – Tushar 2014-09-19 09:59:41