개체가있는 NSMutableArray가 있고 UITableView에서 개체를 추가/제거하는 데 다음 코드를 사용합니다. 앱을 닫은 후 다시 실행 한 후에 만 작동하지만 곧바로 실행되지는 않습니다. 왜 이런거야? 여기 내 코드입니다 (maincelltext은 셀의 제목이며 subtitlecelltext 자막입니다) :NSMutableArray 객체가 UITableView에 바로 추가되지 않는 이유는 무엇입니까?
maincelltext = [[NSMutableArray alloc] init];
subtitlecelltext = [[NSMutableArray alloc] init];
[maincelltext addObject:@"TITLE"];
[subtitlecelltext addObject:@"SUBTITLE TEST"];
편집이 :
- (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;
}
감사 : 여기 내 jQuery과 코드입니다!
좀 더 자세하게 게시 할 수 있습니까? 이 질문은 다음과 같이 사용할 수 없습니다 –
질문을 이해하고 코드를 게시하기에 충분하지 않습니다. 이 방법으로 테이블에 요소를 추가하거나 제거하지 않고 배열에서 요소를 제거 할 수 있습니다. – Mat
지금 편집 :-) – pixelbitlabs