xcode - How to add different Custom Cells in one TableView with Storyboard? -
i want add 2 or more diffrent custom cells in 1 tableview, using storyboard. know how add diffrent cells without storyboard. 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 question: how can storyboard? add 1 custom cell possible. can not add 2 diffrent cell. can me please?
in attributes inspector table view, select "dynamic prototypes" , below select number of prototype cells. give each cell different identifier , when dequeuing cells in cellforrowatindexpath
, use appropriate identifier based on indexpath.
- (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... }
Comments
Post a Comment