2010-08-11 43 views
0

嘿人們即時將我的字符串數組加載到tableview中,我已經做了解析信息並將需要的數據存儲到名爲statues1的元素的mutablearray中,現在我想要的要做的是將statues1加載到表格視圖中,並自定義標籤,以便用戶可以看到所有的值,現在我的問題是,當我加載表格視圖時會給出錯誤「」BAD EXCESS「,請幫我解決這個?從可變數組中加載tableview

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    int counter=indexPath.row; 

    NSString *CellIdentifier = [NSString stringWithFormat:@"%d",counter]; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
     cell.selectionStyle=UITableViewCellSelectionStyleNone; 

     UIImageView *imgViewBack=[[UIImageView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 100.0)]; 
     imgViewBack.image=[UIImage imageNamed:@"black-_image.png"]; 
     [cell.contentView addSubview:imgViewBack]; 

     if(statuses1) 
     { 
      UILabel *lblTitle=[[UILabel alloc] initWithFrame:CGRectMake(100.0, 10.0, 200.0, 20.0)]; 
      lblTitle.text=[statuses1 objectAtIndex:indexPath.row]; 
      [cell.contentView addSubview:lblTitle]; 
      [lblTitle release]; 
     }       
     //[cell.contentView addSubview:btnRowButton]; 
    }    
    return cell; 
} 

回答

0

而不是增加一個新的標籤,查看每個單元格,可以

cell.detailTextLabel.text = [statuses1 objectAtIndex:indexPath.row]; 

我不確定,但之後的版本可能會導致錯誤。你只是檢查出跟蹤回溯,看看你是否可以找出導致它的原因(帶有錯誤的小黃色按鈕)

+0

OP的'lblTitle''釋放'是適當的,因爲他調用'alloc/init '。 – 2010-08-11 16:18:21

+0

但我必須在桌子上顯示幾個標籤,所以我必須定製它。因爲應用上述結果給出「不良後果」 – 2010-08-11 16:19:47

+0

@Jacob,你是對的。 @Prash,你有沒有嘗試看回溯? (這是應用程序運行時的Shift-Command-Y) – 2010-08-11 16:23:37