私のuitableviewには2つのセクションがあります
最初はコアデータからフェッチされます
その他は、NSMutableArray(otherFriends)に格納されているテキストフィールドを介して追加されます
これが私のコードです
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
if([otherFriends count]>0)
{
return 2;
}
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)sectionIndex
{
if(otherFriends == 0)
{
return [[[[self fetchedResultsController]sections]objectAtIndex:0]numberOfObjects];
}
return [otherFriends count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"newGroupCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
cell.textLabel.font = [UIFont fontWithName:@"Helvetica-Light" size:20.0];
cell.textLabel.backgroundColor = [UIColor colorWithWhite:1.0f alpha:0.0f];
if(indexPath.section == 0)
{
user = [[self fetchedResultsController] objectAtIndexPath:indexPath];
cell.textLabel.text = user.name;
cell.detailTextLabel.text = user.primaryResource.status;
[cell.imageView setFrame:CGRectMake(0, 0, 50, 50)];
[cell.imageView.layer setMasksToBounds:YES];
if (user.photo != nil)
{
cell.imageView.image = user.photo;
}
else
{
cell.imageView.image = [UIImage imageNamed:@"defaultPerson"];
}
}
else
{
cell.textLabel.text = [otherFriends objectAtIndex:indexPath.row];
cell.imageView.image = [UIImage imageNamed:@"defaultPerson"];
}
return cell;
}
最初のセクションにも字幕がありますが、2番目のセクションのセルには字幕がありません
新しい友達を追加するときは、すべての行が表示されるまで正常に機能しますが、新しい友達を追加してその行が表示されず、その行を表示するにはスクロールする必要があります。この行には、セクション0の最初の行のサブタイトルが表示されます(非常に最初のセル)とセクション1の3行目で繰り返されます。字幕だけが繰り返されていますが、本文は繰り返されていません。
数時間の間、私はこれを理解しようとしていますが、運がありません。