views:

31

answers:

1

Hi All,

I am trying to make a details page similar to the address book app on the iphone, but am having trouble, organising the data and also the view.

I am currently going down this route, but there has to be an easier way:

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

    if (indexPath.section == 0) {
        UITableViewCell *cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"] autorelease];
        cell.textLabel.text = [selectedData objectForKey:@"name"];;
        cell.detailTextLabel.text = [selectedData objectForKey:@"title"];

        NSString *imageFile = [[NSBundle mainBundle] pathForResource:@"contact-detail" ofType:@"png"];
        UIImage *ui = [[UIImage alloc] initWithContentsOfFile:imageFile];
        cell.imageView.image = ui;
        cell.backgroundColor = [UIColor groupTableViewBackgroundColor];
        return cell;
    }

    if (indexPath.section == 1) {
        UITableViewCell *cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:@"cell"] autorelease];
        cell.textLabel.text = @"Telephone";
        cell.detailTextLabel.text = [selectedData objectForKey:@"telephone"];
        return cell;
    } else {
        UITableViewCell *cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:@"cell"] autorelease];
        cell.textLabel.text = @"Address";
        cell.detailTextLabel.text = [selectedData objectForKey:@"address"];
        return cell;
    }    
}

In the selectedData dictionary I have thing like telephone, name, title, email etc. Not all completed.

As the the display for the name, I want it to show the same as the address book, but can't seem to remove the border around the cell.

Any help or pointers on this welcome...

**Edit

I have added a new post for the data arrangement but simplified the question, I want to thank Larsaronen and mark it as correct answer for his post as this really helped.

New simplified post

+1  A: 

One easy thing to do would be to add the photo and name to the tableHeaderView instead of a cell..

Larsaronen
I have never heard of 'tableHeaderView' Just had a play and sorted that part of the problem. Thanks
jimbo