下面是我的code.Which,用于在表的部分显示内容,然后单击
-(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按下部分,给了我一个糟糕的访问错误。
发布于 2014-10-07 08:36:36
而不是在内容视图上添加子视图
https://stackoverflow.com/questions/25930634
复制相似问题