iphone - TableView with multiple switches -


i have tableview multiple of switches(one switch each row). best way save state switches? , in methods should save , retrieve data?

save data in array, haven't given context may using array of sort drive number of rows in table , rest of content?

you set value of switch in cellforrowatindexpath: method. i've assumed following:

  • you have pointer switch within cellforrowatindexpath method
  • you have created mutable array , filled nsnumber objects

so, when you've got cell , return it:

cellswitch.on = [[switchvaluearray objectatindex:indexpath.row] boolvalue]; 

your setter method little more complicated because of switches calling same action method. therefore need find out row switch in. in method you've connected value changed of switch

-(ibaction)switchvaluechanged:(uiswitch*)sender {     nsindexpath *indexpath = [self.tableview indexpathforcell:(uitableviewcell*)[sender superview]];     [switchvaluearray replaceobjectatindex:indexpath.row withobject:[nsnumber numberwithbool:sender.on]]; } 

Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -