ios - One IBAction for multiple custom prototype cells with buttons -
using storyboard, have table view controller containing multiple dynamic prototype cells. 1 of cells custom dynamic prototype cell (for created subclass) containing label , switch. have action switch wired action method (say switchchanged:) in view controller. in cellforrowatindexpath, configure , return cell appropriate specified index. far good.
the problem: application has multiple instances of these custom cells, how differentiate switch has changed? 1 thought in view controller can create member switch each cell , link them specific cell switch when cellforrowatindexpath called first time. can use these member switches compare switch passed switchchanged:.
i know can try , immediate answer, hoping discussion of how other developers trying do. best/worst/ok approach , practical alternatives?
regards,
--john
i had situation once (not switches, believe applies same). i've managed around subclassing object class , adding required properties/methods inside subclass.
when calling action, sender subclass, , can access added code there.
i don't know if case, if you're trying change value, should use bind switch value property when creating object. not need ibaction call.
edit: example:
@interface myswitch : uiswitch @property (nonatomic, assign) nsuinteger someproperty; @end
then, every time create cell, can set "someproperty" want.
-(uitableviewcell*)tableview:(uitableview*)tableview cellforrowatindexpath:(nsindexpath*)indexpath { // yada yada yada... uitableviewcell *cell; // yada yada yada... [cell.mylinkedswitch setsomeproperty:indexpath.row]; return(cell); }
unless you're not creating cells using tableview:cellforrowatindexpath:
method. should use bindings value right place.
Comments
Post a Comment