首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UItableview剖面上长抽头的访问错误

UItableview剖面上长抽头的访问错误
EN

Stack Overflow用户
提问于 2014-09-19 09:27:19
回答 1查看 129关注 0票数 0

下面是我的code.Which,用于在表的部分显示内容,然后单击

代码语言:javascript
复制
    -(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];
    }
}

}

我使用这段代码来显示数据,重新加载部分的数据,按钮上的数据,click.Long按下部分,给了我一个糟糕的访问错误。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-10-07 08:36:36

而不是在内容视图上添加子视图

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25930634

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档