ios - how to return one of two types of custom table view cells in cellForRowAtIndexPath in objective c -
i have table view controller 2 different prototype cells: 1 story posted , other picture or out story. after research have found have use switch or if statement in
- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath object:(pfobject*)object to achieve this. way want filter using key on parse either contains picture or story each post. have put code cant seem make work appreciated , can clarify doesn't make sense.
- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath object:(pfobject *)object { pfobject *filter = [pfobject objectwithclassname:@"post"]; nsstring *cellfilter = [filter objectforkey:@"cellfilter"]; if (cellfilter == @"picture") { static nsstring *cellindentifier = @"picturecell"; uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:cellidentifier]; //assign data labels , image view return cell; }else{ static nsstring *cellindentifier = @"storycell"; uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:cellidentifier]; //assign data labels return cell; } }
you need more this:
- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { pfobject *filter = [pfobject filterforrowatindexpath:indexpath]; nsstring *cellfilter = [filter objectforkey:@"cellfilter"]; /* insert code returning cell based on cellfilter */ } if don't implement method uitableviewdatasource protocol never called. adding own "object" parameter means it's unknown table view.
additionally, need implement method (filterforrowatindexpath in above example) return different filter depending on table row that's being queried.
Comments
Post a Comment