我有一个NSMutableArray内的对象,我使用下面的代码来添加/删除对象从UITableView。它的工作原理,但只有关闭和重新启动应用程序后,不要马上。为什么是这样?这里是我的代码(maincelltext是在细胞中的标题和subtitlecelltext是字幕):为什么我的NSMutableArray对象不能直接添加到UITableView中?
maincelltext = [[NSMutableArray alloc] init];
subtitlecelltext = [[NSMutableArray alloc] init];
[maincelltext addObject:@"TITLE"];
[subtitlecelltext addObject:@"SUBTITLE TEST"];
编辑:这是我的UITableView代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
cell.textLabel.font = [UIFont fontWithName:@"HelveticaBold" size:16.0];
cell.textLabel.adjustsFontSizeToFitWidth = YES;
cell.textLabel.numberOfLines = 1;
// Configure the cell.
UIImage *cellImage = [UIImage imageNamed:@"warning.png"];
CGRect cropRect = CGRectMake(0.0, 0.0, 12.0, 12.0);
CGImageRef croppedImage = CGImageCreateWithImageInRect([cellImage CGImage], CGRectMake(0.0f,0.0f,cellImage.size.width,cellImage.size.height));
UIImageView *myImageView = [[UIImageView alloc] initWithFrame:cropRect];
[myImageView setImage:[UIImage imageWithCGImage:croppedImage]];
CGImageRelease(croppedImage);
[self.view addSubview:myImageView];
cell.imageView.image = cellImage;
NSString *subjectString = [maincelltext objectAtIndex: [indexPath row]];
cell.textLabel.text = subjectString;
NSString *subtitle = [subtitlecelltext objectAtIndex: [indexPath row]];
cell.detailTextLabel.text = subtitle;
if(maincelltext.count == 0){
NSString *notabledata = [NSString stringWithFormat:@"No Dates Set"];
[maincelltext addObject:notabledata];
}
return cell;
}
谢谢!
你可以请张贴一些更多的细节。此问题无法如此 –
这不足以理解您的问题,发布更多代码。用这种方式更多的是,你不是从表中添加/删除元素,而是从数组中删除元素。 – Mat
现在编辑为你:-) – pixelbitlabs