簡體   English   中英

dequeueReusableCellWithIdentifier forIndexPath

[英]dequeueReusableCellWithIdentifier forIndexPath

我有一個使用NSLayoutConstraints的自定義/子類UITableViewCell。 最左邊的UIImageView可能會或可能不會填充圖像,如果沒有,此字段右側的對象將自然地向左移動。 在自定義UITableViewCell中運行良好,但是我將使用我的自定義UITableViewController填充內容。 不幸的是,下面的代碼將使用圖像填充每行cell.dispatchedView - 盡管我已經陷入了不填充任何內容的行。

這與dequeueReusableCellWithIdentifier有關。 想法?

static NSString *CellIdentifier = @"CellIdentifier";


- (void)viewDidLoad {
    [super viewDidLoad];

    [self.tableView registerClass:[NXGActiveUnitsCell class] forCellReuseIdentifier:CellIdentifier];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath {

    NSDictionary *item = [self.model.dataSource objectAtIndex:indexPath.row];

    NXGActiveUnitsCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    if([[[item objectForKey:@"cfs_no"] clean] length] > 0) {
        cell.dispatchedView.image = [UIImage imageNamed:@"p.png"];
        NSLog(@">>>%@",[item objectForKey:@"cfs_no"] );
    } else {
        NSLog(@">>> i got nothing so I should not touch this row...");
    }

    cell.departmentIconView.image = [UIImage imageNamed:@"f.png"];
    cell.unitLabel.text = [item valueForKey:@"unit_id"];

    return cell;
}

我不知道這是否已經解決了你的問題,但你應該確定

cell.dispatchedView.image = nil;

在else-case中,因為細胞被重用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM