Я добавляю две UILabels
к UITableViewCell
, а затем к этой ячейке добавляем метки имени и номера. Когда я перезагружаю данные в UITableView
(добавляю ли я или удаляю контакт из табличного представления), данные в метках перекрываются, что означает, что метки не перезагружаются, пока не будет перезагружено все представление.
Может кто-нибудь помочь, пожалуйста?
Код:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UILabel *name;
UILabel *number;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
//NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES];
// NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor];
// [sortDescriptor release];
}
CGRect Label1Frame = CGRectMake(10, 10, 140, 25);
name = [[UILabel alloc] initWithFrame:Label1Frame];
name.tag = 1;
[name setBackgroundColor:[UIColor clearColor]];
[cell.contentView addSubview:name];
CGRect Label2Frame = CGRectMake(150, 10, 140, 25);
number = [[UILabel alloc] initWithFrame:Label2Frame];
number.tag = 1;
[number setBackgroundColor:[UIColor clearColor]];
[cell.contentView addSubview:number];
name.text = [NSString stringWithFormat:@"%@",[names objectAtIndex:indexPath.row]];
number.text = [NSString stringWithFormat:@"%@",[phonenumbers objectAtIndex:indexPath.row]];
[name release];
[number release];
return cell;
}