views:

28

answers:

1

Hi All,

Apologies if this is a simple question but googling hasn't been able to help me. I am planning to display 3 arrays of data in a Table View that has each array in a different section in the Table View.

Can any one provide me with a link to a good tutorial or sample code that could help me with this?

Once again I apologize if this is a simple question and answer but I am a newbie to Xcode and working on my first serious project for it.

Thanks!

+1  A: 

In your TableViewController implement:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 3;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{
 return [[self getDataArray:section]count];//implement getDataArray
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{

    static NSString *CellIdentifier = @"Cell";

    NSObject *data = [[self getDataArray:indexPath.section]objectAt:indexPath.row];//implement getDataArray

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) 
    {
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
         //add Code to populate cell with data
    }
    return cell;
}

Other methods to probably implement:

- (UIView *)tableView: (UITableView *)tableView viewForHeaderInSection: (NSInteger)section
- (CGFloat)tableView:(UITableView *)aTableView heightForHeaderInSection:(NSInteger)section
Kai
Many Thanks, I didn't realise it was as easy as this. I had most of this code implemented anyway I just needed to finalise it! Thanks Again for taking the time to answer.
Louis Russell