2011-06-10 56 views
-1

我怎樣才能從我的桌子上點擊按鈕點擊數據。 我在我的表格視圖中添加了5張圖片。下次我只添加3張圖片,但最後的4張和5張圖片不會從我的表格視圖中刪除。任何人都可以爲我提供一個很好的方法來做到這一點。如何從按鈕單擊的表格視圖中刪除數據?

我的代碼是

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


static NSString *CellIdentifier = @"Cell"; 

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) { 
    cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease]; 
} 


     if(indexPath.row == 0) 
     { 
     UIImageView *imageView1 = [[UIImageView alloc] initWithFrame:CGRectMake(0,5,100,125)]; 

     if([imageArray count]>0) 
     { 
     imageView1.image = [imageArray objectAtIndex:0]; 
     [cell.contentView addSubview:imageView1]; 
     [imageView1 release]; 
     } 
     if([imageArray count]>1) 
     { 
     UIImageView *imageView2 = [[UIImageView alloc] initWithFrame:CGRectMake(150,5,100,125)]; 
     imageView2.image = [imageArray objectAtIndex:1]; 
     [cell.contentView addSubview:imageView2]; 
     [imageView2 release]; 
     } 
     if([imageArray count]>2) 
     { 
     UIImageView *imageView3 = [[UIImageView alloc] initWithFrame:CGRectMake(310, 5, 100, 125)]; 
     imageView3.image = [imageArray objectAtIndex:2]; 
     [cell.contentView addSubview:imageView3]; 
     [imageView3 release]; 
     } 
     if([imageArray count]>3) 
     { 
     UIImageView *imageView4 = [[UIImageView alloc] initWithFrame:CGRectMake(460,5,100,125)]; 
     imageView4.image = [imageArray objectAtIndex:3]; 
     [cell.contentView addSubview:imageView4]; 
     [imageView4 release]; 
     } 

     } 
     else if(indexPath.row == 1) 
     { 
     if([imageArray count]>4) 
     { 
     UIImageView *imageView5 = [[UIImageView alloc] initWithFrame:CGRectMake(0,5,100,125)]; 
     imageView5.image = [imageArray objectAtIndex:4]; 
     [cell.contentView addSubview:imageView5]; 
     [imageView5 release]; 
     } 
     if([imageArray count]>5) 
     {  
     UIImageView *imageView6 = [[UIImageView alloc] initWithFrame:CGRectMake(150,5,100,125)]; 
     imageView6.image = [imageArray objectAtIndex:5]; 
     [cell.contentView addSubview:imageView6]; 
     [imageView6 release]; 
     } 

     if([imageArray count]>6) 
     { 
     UIImageView *imageView7= [[UIImageView alloc] initWithFrame:CGRectMake(310, 5, 100, 125)]; 
     imageView7.image = [imageArray objectAtIndex:6]; 
     [cell.contentView addSubview:imageView7]; 
     [imageView7 release]; 
     } 

,並點擊一個按鈕我從我的數組中刪除所有對象。並只添加3個圖像。 然後調用myTableView.reloadData();

但前三個正在改變,剩下的4個& 5仍然沒有刪除。

回答

0

只是一種預感,但你可能要檢查您的tableView的實現:numberOfRowsInSection:

請後,如果您還是有問題。

+0

numberOfSectionsInTableView是1 – Christina 2011-06-10 17:45:13

+0

您正在第一行中添加圖像0到3(前4個圖像)。第二排第四張圖片。我們得到的印象是共有5排。這些圖像由於其幀分配在另一個之下而以單獨的單元格出現在另一個之下。基本上,這些圖像根本不會被添加到單獨的行中。 – 2011-06-10 17:53:54

+0

和您從imageArray中刪除項目,而不僅僅是將值設置爲零?然後再調用reloadData,對嗎? – picciano 2011-06-10 17:55:55

相關問題