ios - double Tap a UITableView -


i try open uialertview 2 textfield text cell selected. use code:

-(void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath {         uitapgesturerecognizer *taprecognizer = [[uitapgesturerecognizer alloc] initwithtarget:self action:@selector(edit:)];     taprecognizer.numberoftapsrequired = 2;     [self.view addgesturerecognizer:taprecognizer];      [taprecognizer requiregesturerecognizertofail:taprecognizer];       cardtableviewcell *cell = [tableview dequeuereusablecellwithidentifier:@"editcell" forindexpath:indexpath];     nsstring *cellfirsttext = cell.cellfirsttext.text;     nsstring *cellsecondtext = cell.cellsecondtext.text;      [[nsuserdefaults standarduserdefaults] setobject:cellfirsttext forkey:@"cellfirsttoedit"];     [[nsuserdefaults standarduserdefaults] setobject:cellsecondtext forkey:@"cellsecondtoedit"]; }  -(void)edit: (uitapgesturerecognizer *)sender {      uialertview *alert = [[uialertview alloc] initwithtitle:@"title" message:@"message" delegate:self cancelbuttontitle:@"cancel" otherbuttontitles:@"save", nil];      alert.alertviewstyle = uialertviewstyleloginandpasswordinput;      [[alert textfieldatindex:1] setsecuretextentry:no];      [alert textfieldatindex:0].text = [[nsuserdefaults standarduserdefaults] objectforkey:@"cellfirsttoedit"];     [alert textfieldatindex:1].text = [[nsuserdefaults standarduserdefaults] objectforkey:@"cellsecondtoedit"];      alert.tag = 3;      [alert show]; } 

but problem is, click (ones) on row, text changed default text. hope understand mean.

i think code wrong cause creating uitapgesturerecognizer every time user taps on cell, not when cell loads, , you're assigning view, not cell.

so try this:

move code:

uitapgesturerecognizer *taprecognizer = [[uitapgesturerecognizer alloc] initwithtarget:self action:@selector(edit:)]; taprecognizer.numberoftapsrequired = 2; [self.view addgesturerecognizer:taprecognizer];  [taprecognizer requiregesturerecognizertofail:taprecognizer]; 

to cellforrowatindexpath method after initialize cell, , change [self.view addgesturerecognizer:taprecognizer]; [cell addgesturerecognizer:taprecognizer]; cause want add gesture cell not view.

i don't know if solve problem, 2 things think wrong in code. in theory should work.

edit:

also try setting message on alert initialization nil. also, necessary use nsuserdefaults store variables? can't stored in 2 nsstring properties, or persisting variables reason?


Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -