我有一個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