0

uitableview 单元重用单元...但我不想重用单元。tableView 正在滚动单元格中的文本被删除。所以我想在 didloadview 中创建所有单元格。这段代码怎么写??!!

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
//test
setting_detail_cell *customCell = (setting_detail_cell*)[tableView cellForRowAtIndexPath:indexPath];***

NSString *keyword1 = [[customCell Key1] text];
//
setting_cell=[tableView dequeueReusableCellWithIdentifier:CellTableIdentifier];

rowData = self.PPT_Setting[indexPath.row];
[setting_cell setNumber:rowData[@"page_num"]];
    @try {
        rowData_keyword =self.Keyword_list[indexPath.row];
        setting_cell.Key1.text = rowData_keyword[@"key1"];
        setting_cell.Key2.text = rowData_keyword[@"key2"];
        setting_cell.Key3.text = rowData_keyword[@"key3"];
        NSLog(@"index1 : %d",indexPath.row);;
        NSLog(@"cell : %@",setting_cell);

        if ([rowData_keyword[@"key1"] isEqualToString:@"(null)"] == YES) {
            setting_cell.Key1.text = @" ";
        }
        if ([rowData_keyword[@"key2"] isEqualToString:@"(null)"] == YES) {
            setting_cell.Key2.text = @" ";
        }
        if ([rowData_keyword[@"key3"] isEqualToString:@"(null)"] == YES) {
            setting_cell.Key3.text = @" ";
        }
    }@catch (NSException *exception) {
        NSLog(@"%@",exception);
    }

return  setting_cell;
}
4

2 回答 2

0

查找单元格是否可重用。因为您的代码单元未重用。

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath (NSIndexPath*)indexPath 
{
    static NSString *cellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];

    if (!cell)
        cell = [[UITableViewCell alloc] initWithStyle:yourStyle reuseIdentifier: cellIdentifier];

    return cell;
}

用于唯一标识

UITableViewCellAccessoryCheckmark类型

于 2014-02-14T08:32:48.150 回答
0

如果您有很多要显示的单元格,并且在设置单元格时使用了过多的内存,则会导致内存开销。为了避免这个苹果使用可重复使用的细胞。

如果您确定要静态分配单元格,则创建单元格并将其保存在数组中,然后返回相应索引处的单元格(不推荐使用此方法)。

于 2014-02-14T08:41:46.837 回答