Question

uitableview cell reuses cells... but I don`t want to reuse cells. tableView is scrolling that text in cell is deleted. so I want to create all cells in didloadview. How to write this code??!!

- (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;
}
Was it helpful?

Solution

If you have lot of cells to display and too much memory is using when setting up a cell, it will cause memory overhead. To avoid this apple using reusable cells.

If you are sure you want statically allocated cells, then create cells and keep it in an array then return the cell at corresponding index(this method is not recommended).

OTHER TIPS

find cell is reuse or not. because your code cell not reused.

-(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;
}

for unique identification use

UITableViewCellAccessoryCheckmark type

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top