开发者

Crazy TableView (Or more likely me being just a jerk) ;-)

I'm going crazy with all that objective C.

I went to bed at 1.30 pm today, spending the night on my app but I love it...

Well that's not the point anyway...

My question is ....

I have a table view which evaluates a statement when it displays its data : it goes like this :

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

static NSString *CellIdentifier = @"CustomCell";

cell = ((MainCell *)[self.tableView dequeueReusableCellWithIdentifier:CellIdentifier]);
if (cell == nil) {

        [[NSBundle mainBundle] loadNibNamed:@"MainCell" owner:self options:nil];

        }

    Entry *entry = [fetchedResultsController objectAtIndexPath:indexPath];
    cell.topLabel.text = [@"* 开发者_开发百科" stringByAppendingString: entry.entryname];
    cell.bottomLabel.text = entry.textbody;


    if ([entry.active boolValue] == YES) {
        cell.cellImageView.image = [UIImage imageNamed:@"check.png"];
    }
    else {
        cell.cellImageView.image = nil;
        cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;

    }

    return cell;
 }

The problem is that the first time it displays the data, the conditions are met when I scroll down the tableview but when I scroll up, sometimes, I get my "check.png" image and the accessory as well, which is not possible normally.

Am I going crazy or is it the tableview ?

Could you help me with that please, I can't figure out why it doesn't work... :-((

Thanks a lot in advance.

Mike


When the cells are getting reused, you're only setting the image or accessory, you're not clearing the accessory in the first case. So when you reuse a cell with an accessory, it might have the accessory still on it from last time you used it even if it's not active.


Waouh, it's working now. Thanks a million.

the code was

if ([entry.active boolValue] == YES) {
    cell.cellImageView.image = [UIImage imageNamed:@"check.png"];
}
else {
    cell.cellImageView.image = nil;
    cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;

}

but it should have been :

if ([entry.active boolValue] == YES) {
    cell.cellImageView.image = [UIImage imageNamed:@"check.png"];
    cell.accessoryType = UITableViewCellAccessoryNone;
}
else {
    cell.cellImageView.image = nil;
    cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜