質問

i want to add 2 or more diffrent Custom cells in one Tableview, by using storyboard. i know how to add diffrent cells without storyboard. I always do this by this way:

static NSString *CellIdentifier = @"Cell";
CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
//pictureCell = [[DetailPictureCell alloc]init];//(DetailPictureCell *)[tableView dequeueReusableCellWithIdentifier: CellIdentifier];
pictureCell.header = true;
[pictureCell setHeader];
if (cell == nil) {
    if ([indexPath row] == 0) {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"HeaderAngebotViewCell" owner:self options:nil];
        NSLog(@"New Header Cell");
}
    if([indexPath row] ==1){
    NSArray *nib = [[NSBundle mainBundle]loadNibNamed:@"productCell" owner:self options:nil];
        cell = [nib objectAtIndex:0];
}

And now my question: How i can do this with storyboard? To add one custom cell is possible. But i can not add two diffrent cell. Can you help me please?

役に立ちましたか?

解決

In the attributes inspector for the table view, select "Dynamic Prototypes" and below that select the number of prototype cells. Give each cell a different identifier and when dequeuing cells in cellForRowAtIndexPath, use the appropriate identifier based on indexPath.

enter image description here

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *identifier;
    if (indexPath.row == 0) {
        identifier = @"OneCellId";
    } else if (indexPath.row == 1) {
        identifier = @"OtherCellId";
    }
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];

    //configure cell...
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top