Sunday, 15 March 2015

objective c - How to replace an existing value with another value through it's id in iOS? -



objective c - How to replace an existing value with another value through it's id in iOS? -

how set value specific textfield of particular row according index? results updates @ bottom or lastly cell...

currently calls on current value. problem issue not update current row lastly row of index path.

.h file

//when label1 , label 2 connected causes programme crash. connection cannot have prototype outlet destination

@property (nonatomic, strong) iboutlet uilabel *label1; //not connected @property (nonatomic, strong) iboutlet uilabel *label2; //not connected @property (nonatomic, weak) iboutlet uistepper *stepper; // not conneted -(ibaction)stepperchangedvalue:(uistepper *)sender; //connected uistepper

.m file

-(ibaction)stepperchangedvalue:(uistepper *)sender{ //my incremental number here nsinteger = [sender value]; nslog(@"value: %i",i); uitextfield *textfield = (uitextfield*)[self.view viewwithtag:2]; textfield.text = [nsstring stringwithformat:@"%d",i ]; //find row # uitableviewcell *cell = (uitableviewcell *)[[sender superview] superview]; nsindexpath *indexpath = [self.tableview indexpathforcell:cell]; nslog(@"value: %i",indexpath.row); //i have row index here //how set sender value right row of table? } // homecoming number of sections in table (always 1 demo!) - (nsinteger)numberofsectionsintableview:(uitableview *)tableview { homecoming [mydata count]; } // homecoming amount of items in our table (the total items in our array above) - (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section { homecoming [mydata count]; } // homecoming cell table - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { // cell identifier matches our identifier in ib static nsstring *cellidentifier = @"steppercell"; // create or reuse cell uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:cellidentifier]; if (cell == nil) { cell = [[uitableviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:cellidentifier]; } // cell label using it's tag , set uilabel *celllabel = (uilabel *)[cell viewwithtag:1]; [celllabel settext:[mydata objectatindex:indexpath.row]]; // cell label using it's tag , set uilabel *celllabel2 = (uilabel *)[cell viewwithtag:2]; [celllabel2 settext:@"0"]; homecoming cell; }

thanks guys! appreciate it.

-(ibaction)stepperchangedvalue:(uistepper *)sender{ //find row # uitableviewcell *cell = (uitableviewcell *)[[sender superview] superview]; nsindexpath *indexpath = [self.tableview indexpathforcell:cell]; nslog(@"value: %i",indexpath.row); //i have row index here //my incremental number here nsinteger = [sender value]; nslog(@"value: %i",i); cell.textfield.text = [nsstring stringwithformat:@"%d",i ]; // textfield outlet textfield in cell }

your code should this. need alter text of textfield after cell. , in code , changing text textfield tag 2 , lastly cell textfield may have tag 2. causes problem too.

ios objective-c xcode uitableview

No comments:

Post a Comment