添加/编辑/移动自定义UITableViewCell?

时间:2013-02-26 08:22:53

标签: ios uitableview cocoa-touch uikit nsmutablearray

**的.h

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'

2 个答案:

答案 0 :(得分:0)

显然,数组货币没有[Currency removeObjectAtIndex:indexPath.row]指向的元素;

您已将货币定义为NSMutableArray并且使用Currency = [NSArray arrayWithObjects:usd,eur,aud,nil];

make it [NSMutableArray arrayWithObjects:usd,eur,aud,nil];

答案 1 :(得分:0)

您正在将Currency对象初始化为NSArray

替换

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

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