2013-02-26 107 views
1

**ħ添加/編輯/移動自定義TableViewCell? 。

IBOutlet UITableView *Table; 
NSMutableArray *Currency; 
NSArray *Datacell; 

**創建自定義陣列

Custom *usd = [Custom new]; 
usd.name = @"USD"; 
usd.detail = @"United States Dollar"; 
usd.imageFile = @"usd.jpg"; 


Custom *eur = [Custom new]; 
eur.name = @"EUR"; 
eur.detail = @"Euro Member Countries"; 
eur.imageFile = @"eur.jpg"; 

Custom *aud = [Custom new]; 
aud.name = @"AUD"; 
aud.detail = @"Australia Dollar"; 
aud.imageFile = @"AUD.jpg"; 
Currency = [NSArray arrayWithObjects:usd,eur,aud, nil]; 

重寫以支持編輯表視圖**

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
if (editingStyle == UITableViewCellEditingStyleDelete) { 
// Delete the row from the data source 

    [Currency removeObjectAtIndex:indexPath.row]; 
    [Table reloadData]; 
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade]; 
} 
else if (editingStyle == UITableViewCellEditingStyleInsert) { 
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view 
} 
} 

崩潰:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI removeObjectAtIndex:]: unrecognized selector sent to instance 0x682a0c0' 

回答

0

顯然數組貨幣沒有[Currency removeObjectAtIndex:indexPath.row]指向的元素;

您已將貨幣定義爲NSMutableArray並使用Currency = [NSArray arrayWithObjects:usd,eur,aud,nil]進行了處理。

使它[NSMutableArray arrayWithObjects:usd,eur,aud,nil];

0

您初始化Currency對象作爲NSArray

更換

Currency = [NSArray arrayWithObjects:usd,eur,aud, nil];

Currency = [NSMutableArray arrayWithCapacity:3]; 
[Currency addObject:usd]; 
[Currency addObject:eur]; 
[Currency addObject:aud];