In my app I have a table view with 12 types of custom cells.
I designed each within the storyboard.
In general everything works fine – thanks to your tutorials 🙂
My problem is, that I have individual styles an additional data in each cell – therefore I don’t want them to be reused.
How can I generate a individual custom cell from storyboard to provide it in the –
tableView:cellForRowAtIndexPath:indexPath?
Any suggestions?
Thanks
Dominic
Added:
newCell = [tableView dequeueReusableCellWithIdentifier:cellType];
cell = newCell;
[cell styleWithElement:element andResubItem:resubItem];
my problem is, I need another way to create a custom-styled cell from the storyboard than the quouted above – I have no XIB and the above way is the only way I know to create my cell.
Could it be a solution to create a celltype once the above way and then copy the cell? Is there a way to copy a cell-object?
You can generate a random cell ID each time so it won’t be reused.
However, that would not be very good for scroll performance and memory consumption, so consider actually reusing the cells (i.e. come up with a way to replace data in them).
Edit:
you can always just copy the views from one to another, something along these lines:
You may also need to adjust the frame of myCell to be the same as that of newCell, and if newCell is an action target for any events (e.g. clicking a control element within the cell triggers some action defined in the cell class) you’ll need to reassign those to the myCell, too.
Edit2:
To move actions you could do something like this:
Substitute your new cell for the target – and make sure it implements all the necessary selectors (or you can put a new selector). The code above will replace targets for UIControlEventTouchUpInside – you can use the ones you need instead (or use allControlEvents to enumerate the ones used by a control).