Daniel Ran Lehmann
Daniel Ran Lehmann

Reputation: 377

Multiple CustomCell's in Single UITableView

Trying to get multiple custom cell in just one uitableview, but currently it doesn't work, all it does is to use the first if statement block to set the cell appearance. What should I do? - Thanks for responses, Daniel Ran

Code down below:

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

    if(indexPath.row == 0) {

        //Facebook Tile//
        static NSString *FacebookCellID = @"FacebookCellID";
        FacebookTileCell *FacebookCell = (FacebookTileCell  *)[tableView dequeueReusableCellWithIdentifier:FacebookCellID];

        if (FacebookCell == nil) {

            NSString *XIBStringFacebookTile;
            XIBStringFacebookTile = @"FacebookTileCell";
            NSArray *FacebookTileArray = [[NSBundle mainBundle] loadNibNamed:XIBStringFacebookTile owner:self options:nil];

            NSUInteger FacebookInteger;
            FacebookInteger = 0;
            FacebookCell = [FacebookTileArray objectAtIndex:FacebookInteger];

            UIView *CellSelectedStyle = [[UIView alloc] init];

            UIColor *CellSelectedStyleColor = [UIColor FacebookColor];
            CellSelectedStyle.backgroundColor = CellSelectedStyleColor;

            [FacebookCell setBackgroundView:CellSelectedStyle];


        }

        return FacebookCell;
    }

    else if (indexPath.row == 1) {

    //Twitter Tile//
    static NSString *TwitterCellID = @"TwitterCellID";
    TwitterTileCell *TwitterCell = (TwitterTileCell  *)[tableView dequeueReusableCellWithIdentifier:TwitterCellID];

    if (TwitterCell == nil) {

        NSString *XIBStringTwitterTile;
        XIBStringTwitterTile = @"TwitterTileCell";
        NSArray *TwitterTileArray = [[NSBundle mainBundle] loadNibNamed:XIBStringTwitterTile owner:self options:nil];

        NSUInteger TwitterInteger;
        TwitterInteger = 0;
        TwitterCell = [TwitterTileArray objectAtIndex:TwitterInteger];

        UIView *CellSelectedStyle = [[UIView alloc] init];

        UIColor *CellSelectedStyleColor = [UIColor TwitterColor];
        CellSelectedStyle.backgroundColor = CellSelectedStyleColor;

        [TwitterCell setBackgroundView:CellSelectedStyle];


    }

    return TwitterCell;

    }


}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{

    //refine algorithm//
    return self.view.frame.size.height/NumberofTiles;
    NSLog(@"Flexible Tile Height = %d", NumberofTiles);

    //imbed switch case statement later on//
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    //Just one section in FeedbackTableView//
    return NumberofTiles;

}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return 1;

}

Upvotes: 0

Views: 27

Answers (1)

sha
sha

Reputation: 17860

This is your issue:

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}

You're saying here that you have just one cell.

Upvotes: 2

Related Questions