iphone: проблема с перезагрузкой данных таблицы - PullRequest
0 голосов
/ 19 июля 2011

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

  - (void)viewWillAppear:(BOOL)animated {

    NSFetchRequest *request = [[NSFetchRequest alloc] init];

        NSEntityDescription *entity = [NSEntityDescription entityForName:@"Note" inManagedObjectContext:context];
        [request setEntity:entity]; 
        [request release];    
        [self.tableView reloadData];
    }

    - (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] autorelease];
        }

        // Set up the cell...
        Note *noteItem = [resultController objectAtIndexPath:indexPath];

        //[cell.textLabel setText:[noteItem noteTitle]];    
        //[cell.detailTextLabel setText:[dateFormatter stringFromDate:[noteItem creationDate]]];
        [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
        cell.accessoryView=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"arrow.png"]];

        UILabel *newLabel = [[UILabel alloc] initWithFrame:CGRectMake(5, 5, 200, 19)];
        newLabel.text = [noteItem noteTitle];
        [newLabel setBackgroundColor:[UIColor clearColor]];
        [cell addSubview:newLabel];
        [newLabel release];

        UILabel *detailLabel = [[UILabel alloc] initWithFrame:CGRectMake(5, 20, 200, 26)];
        detailLabel.text = [dateFormatter stringFromDate:[noteItem creationDate]];
        [detailLabel setFont:[UIFont fontWithName:@"Helvetica" size:12.0]];
        [detailLabel setBackgroundColor:[UIColor clearColor]];
        [cell addSubview:detailLabel];
        [detailLabel release];

        [cell setBackgroundColor:[UIColor clearColor]];
         [cell setAlpha:0.6];
        return cell;
    }

Ответы [ 3 ]

2 голосов
/ 19 июля 2011

Создать UILabel в

if (cell == nil) {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
        }

и присвоить его значение за пределами этого условия

0 голосов
/ 19 июля 2011

Ваш метод cellForRowAtIndexPath должен выглядеть следующим образом:

- (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] autorelease];

           nameLabelFrame = CGRectMake(5, 5, 200, 19);
        countLabelFrame = CGRectMake(5, 20, 200, 26);
          UILabel *lblTemp;
            lblTemp = [[UILabel alloc] initWithFrame:nameLabelFrame];
        lblTemp.tag = 1;
        [cell.contentView addSubview:lblTemp];
        [lblTemp release];


        lblTemp = [[UILabel alloc] initWithFrame:countLabelFrame];
        lblTemp.tag = 2;
        [cell.contentView addSubview:lblTemp];
        [lblTemp release];

        }

        // Set up the cell...
        Note *noteItem = [resultController objectAtIndexPath:indexPath];

UILabel *newLabel = (UILabel *)[cell viewWithTag:1];
        newLabel.text = [noteItem noteTitle];
        [newLabel setBackgroundColor:[UIColor clearColor]];



        UILabel *detailLabel = (UILabel *)[cell viewWithTag:2];
        detailLabel.text = [dateFormatter stringFromDate:[noteItem creationDate]];
        [detailLabel setFont:[UIFont fontWithName:@"Helvetica" size:12.0]];
        [detailLabel setBackgroundColor:[UIColor clearColor]];



        [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
        cell.accessoryView=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"arrow.png"]];



        [cell setBackgroundColor:[UIColor clearColor]];
         [cell setAlpha:0.6];
        return cell;
    }
0 голосов
/ 19 июля 2011

Вы должны проверить, если ячейка == ноль. Если это так, то добавьте все метки еще раз, в противном случае они уже были добавлены.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...