Can't give my custom prototype cells in tableview different heights

Posted by kerbelda on Stack Overflow See other posts from Stack Overflow or by kerbelda
Published on 2014-06-05T02:14:39Z Indexed on 2014/06/05 3:25 UTC
Read the original article Hit count: 161

I've looked around at other questions here and many other sources online and just can't find a solution. I have 3 rows and no matter what I do, they all keep the width defined in the tableview. The first one is what I want, but the second and 3rd I can't give a custom height.

Below is my code:

#import "DetailTableViewController.h"
#import "EventDetailTableViewCell.h"
#import "EventDescriptionTableViewCell.h"
#import "EventMapTableViewCell.h"

@interface DetailTableViewController ()
@end

@implementation DetailTableViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 3;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        static NSString *CellIdentifier = @"headerCell";
        EventDetailTableViewCell *headerCell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

        headerCell.headerImage.image = [UIImage imageNamed:@"img4.png"];

        return headerCell;

    } else if (indexPath.section == 1) {
        static NSString *CellIdentifier = @"descriptionCell";
        EventDescriptionTableViewCell *descriptionCell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

        descriptionCell.descriptionImage.image = [UIImage imageNamed:@"img2.png"];

        return descriptionCell;

    } else {
        static NSString *CellIdentifier = @"mapCell";
        EventMapTableViewCell *mapCell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

        return mapCell;
    }
}

#pragma mark - Helper Methods

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    if (section == 1) {
        return @" ";
    } else if (section == 2) {
        return @" ";
    } else {
        return nil;
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
        return 222;
    } else if (indexPath.row == 1) {
        return 80;
    } else {
        return  100;
    }
}
@end

© Stack Overflow or respective owner

Related posts about ios

Related posts about objective-c