iOScell 重用解決辦法

 有時我們項目裏使用tableview時會出現cell重用現象,那是因爲cell被放到一個重用池裏,後面的cell在創建時就會拿這個池子裏cell,,,上代碼   

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    IndexDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:[NSString stringWithFormat:@"Celld%ld", (long)[indexPath row]]];
    if (cell == nil) {
        cell = [[IndexDetailCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:[NSString stringWithFormat:@"Celld%ld", (long)[indexPath row]]];
        cell.mode = self.dataSourse[indexPath.row];
    }
    
    return cell;
    
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章