I have a storyboard with several UITableView. I would like to select a different display type of selected state for UITableViewCell. I explain better.
Going straight to the code I would like to have an enum or flag which drive the type of highlight.
-(void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
switch(cellViewMode) {
case Simple:
[self simpleCell:selected];
break;
case Full:
[self fullCell:selected];
break;
default:
// default method...
break;
}
}
I am looking for the best way to set this cellViewMode flag once and never to be changed, based on the view controller type, considering that actually I am calling my cell in the usual recommended way for storyboard, where the identifier is declared in it, rather than before when there was a static NSString *cellIdentifier in cellForRow: and an if checking the cell existence:
- (UITableViewCell *)tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)indexPath {
Obj *obj = // get obj from datasource
MyTableViewCell *cell = [table dequeueReusableCellWithIdentifier:MyTableCellIdentifier]; // <-- this is how it is done in storyboard
cell.cellTitle.text=obj.titleForCell;
cell.cellDescr.text=obj.descriptionForCell;
return cell;
}
I have specified that I need a flag, but I am open to other solutions, like categories, or whatever may works nice and in elegant way.
After little research, I easily solve this by using the cell identifier property, but using ‘if’ statement because of the nature of identifier.
personally I don’t like ‘if’ statement used like this, but I didn’t fine a better solution.