Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>@Pugal Devan, Well, you can keep the data in one array, but the problem in that case is, you have to take care of array bounds and correct indexes for different sections. For each section indexPath.row will start from index 0, and if your data is in single array, you have to manage the row index by your self. But still if you want to keep it, you can do like: </p> <pre><code>int sectionOneIndex = 0; int sectionTwoIndex = 3; NSMutableArray *sectionArray = [[NSMutableArray alloc] initWithObjects:@"email", @"Name", @"address", @"zipCode", @"country", nil]; </code></pre> <p>Above two integers represents the starting position of elements of your different sections. First 3 objects from the section Array are the part of section One, and last two objects are the part of section two. Now you need to return correct row count. For that you may write:</p> <pre><code>if(section == 0) return [sectionArray count] - (sectionTwoIndex-1); //returns 3 else if(section == 1) return [sectionArray count] - sectionTwoIndex; //returns 2 </code></pre> <p>OR if your count is static you may put constant values in return.</p> <p>And at the time you read from array, you will just add this index in row value, which will return the correct position of your element for the current cell.</p> <pre><code>// Customize the appearance of table view cells. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; } // Configure the cell. if(indexPath.section == 0){ cell.textLabel.text = [sectionArray objectAtIndex:indexPath.row + sectionOneIndex]; } else if (indexPath.section == 1) { cell.textLabel.text = [sectionArray objectAtIndex:indexPath.row + sectionTwoIndex]; } return cell; } </code></pre>
 

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