Я создал пример приложения, которое вставляет 12 строк в табличное представление. И вставлено нормально. Когда после вставки моих строк я не хочу никаких изменений в тексте во время прокрутки табличного представления. Так что я проверил со строкой indexpath значение UITableViewCell, если оно имеетзначения означают возвращение этой ячейки, в противном случае мы создали новый UITableViewCell.
Мой пример кода ниже
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSLog(@"GlobalCount = %d",GlobalCount);
return GlobalCount;
}
- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *obj = (UITableViewCell*)[tableView cellForRowAtIndexPath:indexPath];
if(obj!=nil)
{
NSLog(@"cell indexpath row = %d",indexPath.row);
NSLog(@"cell text = %d",obj.textLabel.text);
return obj;
}
else {
NSLog(@"obj==nil");
}
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tv dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
if([DataTable count]>0)
cell.textLabel.text = [DataTable objectAtIndex:0];
// Configure the cell.
return cell;
}
Какова моя цель, я не хочу обновлять какой-либо текст (или UITableViewCell) для уже созданных строк indexpath (ячейки). Так что я могу проверить это в cellForRowAtIndexPath, но он всегда возвращает nil. Если ячто-нибудь пропустили?
Я проверил, используя эту строку
UITableViewCell *obj = (UITableViewCell*)[tableView cellForRowAtIndexPath:indexPath];
if(obj!=nil)
Плз, помогите мне?
Заранее спасибо ......