2014-09-19 27 views
0

下面的部分是我的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]; 
    } 
} 

}

我用這代碼顯示關於按鈕點擊部分重新加載部分數據的數據。長按部分給我一個錯誤的訪問錯誤。

+0

問題尋求幫助調試(「爲什麼不是這個代碼的工作?」)必須包括所期望的行爲,一個具體問題或**錯誤**和在問題本身中重現它所需的最短代碼。 – peko 2014-09-19 09:45:05

+0

同意。你是否嘗試過在未捕獲的異常處理程序上設置斷點等明顯的事情。我懷疑您的問題是您的部分重新加載代碼已損壞。 – 2014-09-19 09:48:29

+0

對不起,但它在單擊時工作正常 – Tushar 2014-09-19 09:59:41

回答

0

而不是增加對內容視圖子視圖上添加視圖