开发者

UITableViewCell selection problem

I have created a class named ListCell which is a subclass of UITableViewCell. This is so that I 开发者_运维技巧can put more content in the view such as images, labels, etc. easily, instead of coding inside cellForRowAtIndexPath. I have added a label to display an address in the cell. I have another class, inheriting from NSObject, to hold that address. The address is a string that comes from a web service. I am using the following code to fetch the address from the class named Itemsforcell.

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

    static NSString *cellIdentifier = @"CellIdentifier";

    ListCell *cell = (ListCell *)[tableView dequeueReusableCellWithIdentifier: cellIdentifier];


    if (cell == nil) {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"ListCell" owner:self options:nil];

        cell = (ListCell *)[nib objectAtIndex:1];

    } 
    NSUInteger row = [indexPath row];
    Itemsforcell *items = [self.Itemsforcell objectAtIndex:row];

    cell.address.text = items.address;
    return cell;      

}

My problem is that sometimes my cell doesn't get selected with the first click on it, only after the second. This doesn't happen for all the cells. It happens randomly for any cell, and at times it doesn't occur. I don't know where I am going wrong. Please any body suggest me a solution to this weird problem. Thank you one and all.


Most likely, you're holding up the main thread by downloading that string. You should never carry out network activity on the main thread. Spin it off to its own thread, and when it finishes, change the UI on the main thread.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜