基本上,每当我在我的文本字段中输入内容并将其保存到表中时,以前的条目将被替换为新的条目。如何在可变数组中添加元素并保存最后一项?我试图Objective-C,iOS SDK,NSMutableArray,添加元素并保存数据
[tabledata addObject....
,并在进入
tabledata.lastObject objectAtIndex...
,但没有奏效。
这里是我有:
-(void)viewDidLoad
{
[super viewDidLoad];
titlestring = [[NSUserDefaults standardUserDefaults] objectForKey:@"titlehomework" ];
detailsstring = [[NSUserDefaults standardUserDefaults] objectForKey:@"detailshomework"];
tabledata = [[NSMutableArray alloc] initWithObjects:titlestring, nil];
tablesubtitles = [[NSMutableArray alloc] initWithObjects:detailsstring, nil];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
{
return [tabledata count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
{
UITableViewCell *cell = nil;
cell = [tableView dequeueReusableCellWithIdentifier:@"homeworkcell"];
if(cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"homeworkcell"];
}
cell.textLabel.text = [tabledata objectAtIndex:indexPath.row];
cell.detailTextLabel.text = [tablesubtitles objectAtIndex:indexPath.row];
cell.textLabel.font = [UIFont systemFontOfSize:14.0];
cell.textLabel.backgroundColor = [ UIColor clearColor ];
cell.detailTextLabel.backgroundColor = [UIColor clearColor];
//-----------------------------------------START----------------------------Set image of cell----
cellImage = [UIImage imageNamed:@"checkboxblank.png"];
cell.imageView.image = cellImage;
//--------------------------------------------END---------------------------end set image of cell--
return cell;
}
您需要在您试图将对象添加到'tabledata'数组的位置发布代码。 – PengOne 2012-02-23 23:59:29
*“保存最后一个条目”*中的含义*“如何在可变数组中添加元素并保存最后一个条目”*?你可以发布代码,你试图做到这一点? – sch 2012-02-24 00:05:05