Search code examples
objective-cuitableviewstaticcells

Setting static cells in uitableview programmatically


I am programmatically creating a tableview in objective c. How can I make the cells static programmatically?

Thanks


Solution

  • By using a distinct cell identifier for each one you will get it. You could use something like this:

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        NSString *cellIdentifier = [NSString stringWithFormat:@"s%i-r%i", indexPath.section, indexPath.row];
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
        if (cell == nil)
        {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier] autorelease];
            //you can customize your cell here because it will be used just for one row.
        }
    
        return cell;
    }