objective c - iOS 7 - Take the value of a textField inside a custom tableViewCell from another function -


sorry if title not clear. have application shows tableview , user selects several rows , inputs text in textfield in tableviewcell. after that, presses button submit selections input in textfield.

here searchresulttableviewcell.h

#import <uikit/uikit.h>  @interface searchresulttableviewcell : uitableviewcell  @property (strong, nonatomic) iboutlet uilabel *price; @property (strong, nonatomic) iboutlet uilabel *itemname; @property (strong, nonatomic) iboutlet uilabel *discount; @property (strong, nonatomic) iboutlet uitextfield *quantity; @property (strong, nonatomic) iboutlet uitextfield *discountinput;  @end 

and here cellforrowatindexpath method.

- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath {      static nsstring *itemcellidentifier = @"cellidentifier";     searchresulttableviewcell *tablecell =(searchresulttableviewcell *)[tableview dequeuereusablecellwithidentifier:itemcellidentifier];      //set text labels here --> values taken arrays     [tablecell.price settext:[nsstring stringwithstring:[pricelist objectatindex:indexpath.row]]];     [tablecell.itemname settext:[nsstring stringwithstring:[itemnamelist objectatindex:indexpath.row]]];     [tablecell.discount settext:[nsstring stringwithstring:[discountlist objectatindex:indexpath.row]]];     [tablecell.quantity setkeyboardtype:uikeyboardtypedecimalpad];     [tablecell.discountinput setkeyboardtype:uikeyboardtypedecimalpad];      tablecell.itemname.numberoflines = 0;     tablecell.itemname.linebreakmode = nslinebreakbywordwrapping;      //set check mark , highlights.     if ([[checklist objectatindex:indexpath.row] integervalue] == 1){         tablecell.accessorytype = uitableviewcellaccessorycheckmark;         [tableview selectrowatindexpath:indexpath                                animated:yes                          scrollposition:uitableviewscrollpositionnone];      }     else{         tablecell.accessorytype = uitableviewcellaccessorynone;         [tableview deselectrowatindexpath:indexpath animated:yes];     }      return tablecell;  } 

my issue lies in accessing textfield input own function. here function far:

-(void)preparefinalarray{     //these arrays save selection     itemnamelistfinal = [[nsmutablearray alloc] init];     pricelistfinal = [[nsmutablearray alloc] init];     discountlistfinal = [[nsmutablearray alloc] init];     discountrequestlistfinal = [[nsmutablearray alloc] init];      //use array know positions selected items     nsmutablearray *selecteditems = [[nsmutablearray alloc] init];      //loop @ checklist. checklist array tracks rows selected.     for( int = 0 ; < [checklist count] ; i++ ){         if( [checklist[i] isequaltostring:@"1"] ){             nsnumber *currentelement = [nsnumber numberwithinteger:i];             nslog(@"selected item detected @ %d,", i);             [selecteditems addobject:currentelement];         }     }      //now have index paths, itemnames, discount, user input qty, , user input discount.     for( int = 0 ; < [selecteditems count] ; i++){         //now have indices of selected items, value          //itemnamelist , discountlist arrays, these arrays used populate tableview         [itemnamelistfinal addobject:itemnamelist[[[selecteditems objectatindex:i] integervalue]]];         [discountlistfinal addobject:discountlist[[[selecteditems objectatindex:i] integervalue]]];          //this problem far, want next access tableviewcell         //and quantity , discountinput properties (the textfields)         //so far, managed cell row @ index path         //i not know how proceed after this.          //[self.searchresults cellforrowatindexpath:[[[selecteditems objectatindex:i] integervalue]].row];     } } 

i not know how proceed after this:

[self.searchresults cellforrowatindexpath:[[[selecteditems objectatindex:i] integervalue]].row];

i not know how access quantity , discountinput properties once have row (assuming managed row in code above) , i'm not sure on how input text them. can me? sorry if want tedious.

thank in advance help.

in mvc (model view controller), views visually display information models. code, looks asking views (uitableviewcell's) information should (and is) stored in model class. model objects tableview displaying this:

@interface sale @property (strong, nonatomic) nsstring *itemname; @property (strong, nonatomic) nsnumber *quantity; ... @end 

in tableview:cellforrowatindexpath: method configuring cells , assigning appropriate value name, quantity , discountinput textfields.

- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath {     uitableviewcell *cell = ...     sale *sale = [self.sales objectatindexpath:indexpath.row];     cell.nametextfield.text = sale.itemname;     ... } 

since associate model cell @ given index path (in cellforrowatindexpath), associate given index path model. instead of asking each view properties, store rows of selected cells , find models corresponding rows.

for (nsindexpath *indexpath in selectedindexpaths) {     nsuinteger row = indexpath.row;     sale *sale = self.sales[row];     ...  } 

then handling communication between views , models correctly , code become little simpler read.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -