reloadData не рисует ячейки в табличном представлении - PullRequest
0 голосов
/ 04 августа 2011
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];

NSString *show=[NSString stringWithFormat:@"%@",[res objectAtIndex:18]];
float f=[show floatValue];
show1=[NSString stringWithFormat:@"%.2f %%",f];
[show1  retain];
[self.tableView reloadData];
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = nil;
if (indexPath.row % 2 == 0) {
    // EVEN
    cell = [tableView dequeueReusableCellWithIdentifier:@"EvenCell"];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"EvenCell"] autorelease];
        UIView *bg = [[UIView alloc] initWithFrame:cell.frame];
        UIColor *colour = [[UIColor alloc] initWithRed: (208.0/255.f) green: (231.0/255.f) 
                                                  blue: (241.0/255.f) alpha: 1.0];
        bg.backgroundColor = colour; 
        cell.backgroundView = bg;
        cell.textLabel.backgroundColor = bg.backgroundColor;
        [bg release];
        cell.detailTextLabel.backgroundColor=[UIColor clearColor];
        cell.detailTextLabel.text=show1;
    }
    cell.textLabel.text = [array objectAtIndex:indexPath.row];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

} 
else {
    // ODD
    cell = [tableView dequeueReusableCellWithIdentifier:@"OddCell"];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"OddCell"] autorelease];
        UIView *bg = [[UIView alloc] initWithFrame:cell.frame];

        UIColor *colour = [[UIColor alloc] initWithRed: (143.0/255.f) green: (169.0/255.f) 
                                                  blue: (180.0/255.f) alpha: 1.0];
        bg.backgroundColor = colour;
        cell.backgroundView = bg;
        cell.textLabel.backgroundColor = bg.backgroundColor;
        [bg release];
    }
    cell.textLabel.text = [array objectAtIndex:indexPath.row];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;


} 
return cell;
}   

Это мой код, как вы можете видеть, я перезагружаю данные в viewDidAppear. Show1 - это мои данные, которые нужно поместить в ячейку tableView в detailLabel.text.Теперь не смотрите на мою странную клеточную часть, потому что она не пригодна для использования.Я получил только 1 клетку и ее четную клетку.Теперь моя проблема, когда я удаляю [self.tableView reloadData];строка работает хорошо, не обновляя, но показывает ячейку. Когда я ее кладу, я не вижу ячейку в tableView, она пустая, есть идеи, почему?где я делаю что-то не так?

edit1:

  cell.backgroundView = bg;
    cell.textLabel.backgroundColor = bg.backgroundColor;
    [bg release];
    cell.detailTextLabel.backgroundColor=[UIColor clearColor];
}
cell.detailTextLabel.text=show1;
cell.textLabel.text = [array objectAtIndex:indexPath.row];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

ладно, я изменяю его и получаю из него, если, но все же я не вижу ни одной ячейки таблицы, все ее пустые, только панель навигацииимя и пустая ячейка.Почему его пустое anyidea?

Ответы [ 2 ]

3 голосов
/ 04 августа 2011

Код "cell.detailTextLabel.text = show1;"находится внутри условия if if (cell == nil) Когда вы перезагружаете ячейку, если ячейка уже доступна, вы не попадете в блок кода, и вы изменили значение show1, отображаться не будут.

Код
cell = [tableView dequeueReusableCellWithIdentifier:@"EvenCell"];

Проверяет, является ли их ячейка, которую он может использовать повторно.Если он обнаружит, что он вернет то же самое

3 голосов
/ 04 августа 2011

Строковое значение Show1 устанавливается только во время инициализации ячейки.

cell.detailTextLabel.text=show1;

Поместите вышеуказанную строку ниже этой строки и проверьте.

cell.textLabel.text = [array objectAtIndex:indexPath.row];
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...