Note that there are some explanatory texts on larger screens.

plurals
  1. POUITableView list not displaying all items
    primarykey
    data
    text
    <p>In my UITableView I am trying to display all the items in my plist but its not showing all the items. Actually it is showing most of it but the lower items are being repeated for some odd reason. I basically want to show all the keys in the plist with their respective values. Is the list too long to display? there's about 30 items.</p> <p>First I tried to sort the keys and thought that was the problem, so then I didn't sort at all and I get the same problem, lower down the list the items get repeated and not showing the last 3 items. Is there a limit?</p> <p>Below is some code, I've just modified to fit:</p> <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier1 = @"PreferencesCell1"; static NSString *CellIdentifier2 = @"PreferencesCell2"; static NSString *CellIdentifier3 = @"PreferencesCell3"; UITableViewCell *cell; NSArray *keys = [[[preferences objectAtIndex:indexPath.section] objectForKey:@"Rows"] allKeys]; NSString *prefName = [keys objectAtIndex:indexPath.row]; if (indexPath.section == 0 || indexPath.section == 2) { if(indexPath.section == 0) cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier1]; else if(indexPath.section == 2) cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier2]; if (cell == nil) { if(indexPath.section == 0) cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier1] autorelease]; else if(indexPath.section == 2) cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier2] autorelease]; cell.accessoryType = UITableViewCellAccessoryNone; CGRect labelRect = CGRectMake(10, 5, 300, 31); UILabel *settingName = [[UILabel alloc] initWithFrame:labelRect]; settingName.font = [UIFont boldSystemFontOfSize:17.0]; settingName.backgroundColor = [UIColor clearColor]; settingName.text = prefName; [cell.contentView addSubview: settingName]; [settingName release]; } } else if(indexPath.section == 1) { cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier3]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier3] autorelease]; CGRect labelRect = CGRectMake(10, 5, 300, 31); UILabel *label = [[UILabel alloc] initWithFrame:labelRect]; label.font = [UIFont boldSystemFontOfSize:17.0]; label.backgroundColor = [UIColor clearColor]; label.text = prefName; [cell.contentView addSubview: label]; } cell.accessoryType = UITableViewCellAccessoryNone; cell.selectionStyle = UITableViewCellSelectionStyleNone; } return cell; } </code></pre> <p>What I've found is that if I don't use the labels and just go for the generic cell.textLabel.text approach then all the items are displayed correctly. However if I use the UILabel approach, the bottom items are not shown. I need to go this route as I'm adding other items in the Cell.</p> <p>Working Code. </p> <p>Initialization and creation of cell must be created first, then using that referenced cell remove from superview, then render the subviews. So reordering of the code from above.</p> <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier1 = @"PreferencesCell1"; static NSString *CellIdentifier2 = @"PreferencesCell2"; static NSString *CellIdentifier3 = @"PreferencesCell3"; UITableViewCell *cell; NSArray *keys = [[[preferences objectAtIndex:indexPath.section] objectForKey:@"Rows"] allKeys]; NSString *prefName = [keys objectAtIndex:indexPath.row]; // Create/Initialize Cell first if (indexPath.section == 0 || indexPath.section == 2) { if(indexPath.section == 0) cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier1]; else if(indexPath.section == 2) cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier2]; if (cell == nil) { if(indexPath.section == 0) cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier1] autorelease]; else if(indexPath.section == 2) cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier2] autorelease]; } } else if(indexPath.section == 1) { cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier3]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier3] autorelease]; } } // remove from superview [cell.contentView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)]; // render the subviews if (indexPath.section == 0 || indexPath.section == 2) { cell.accessoryType = UITableViewCellAccessoryNone; CGRect labelRect = CGRectMake(10, 5, 300, 31); UILabel *settingName = [[UILabel alloc] initWithFrame:labelRect]; settingName.font = [UIFont boldSystemFontOfSize:17.0]; settingName.backgroundColor = [UIColor clearColor]; settingName.text = prefName; [cell.contentView addSubview: settingName]; [settingName release]; } else if(indexPath.section == 1) { CGRect labelRect = CGRectMake(10, 5, 300, 31); UILabel *label = [[UILabel alloc] initWithFrame:labelRect]; label.font = [UIFont boldSystemFontOfSize:17.0]; label.backgroundColor = [UIColor clearColor]; label.text = prefName; [cell.contentView addSubview: label]; cell.accessoryType = UITableViewCellAccessoryNone; cell.selectionStyle = UITableViewCellSelectionStyleNone; } return cell; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload