objective c - In app purchase - how to make "Yes" button be "Buy" -
i want rename "yes" button in uialertview
"buy".
here codes.
- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:@"cell" forindexpath:indexpath]; skproduct * product = (skproduct *) _products[indexpath.row]; cell.textlabel.text = product.localizedtitle; [_priceformatter setlocale:product.pricelocale]; cell.detailtextlabel.text = [_priceformatter stringfromnumber:product.price]; if ([[rageiaphelper sharedinstance] productpurchased:product.productidentifier]) { cell.accessorytype = uitableviewcellaccessorycheckmark; cell.accessoryview = nil; } else { uibutton * buybutton = [uibutton buttonwithtype:uibuttontyperoundedrect]; buybutton.frame = cgrectmake(0, 0, 72, 37); [buybutton settitle:@"buy" forstate:uicontrolstatenormal]; buybutton.tag = indexpath.row; [buybutton addtarget:self action:@selector(buybuttontapped:) forcontrolevents:uicontroleventtouchupinside]; cell.accessorytype = uitableviewcellaccessorynone; cell.accessoryview = buybutton; } return cell; } - (void)buybuttontapped:(id)sender { uibutton * buybutton = (uibutton *)sender; skproduct *product = _products[buybutton.tag]; nslog(@"buying %@...", product.productidentifier); [[rageiaphelper sharedinstance] buyproduct:product]; }
by far, "buy" operation in cells work.
- (void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath { [tableview deselectrowatindexpath:indexpath animated:yes]; uitableviewcell * cell = [tableview cellforrowatindexpath:indexpath]; if (cell.accessorytype == uitableviewcellaccessorycheckmark) { uistoryboard * storyboard = [uistoryboard storyboardwithname:@"main" bundle:nil]; ssdetailviewcontroller * detailviewcontroller = [storyboard instantiateviewcontrollerwithidentifier:@"detail"]; [self.navigationcontroller pushviewcontroller:detailviewcontroller animated:yes]; } else { uialertview * alertview = [[uialertview alloc] initwithtitle:@"cell selected buy" message:@"tap \"yes\" confirm purchase" delegate:self cancelbuttontitle:@"cancel" otherbuttontitles:@"yes", nil]; [alertview show]; } } - (void)alertview:(uialertview *)alertview clickedbuttonatindex:(nsinteger)buttonindex { if (buttonindex == 0) { nslog(@"cancel"); } else { nslog(@"yes"); // **here want make "buy" operation, how `button.tag` in tapped cell?** //skproduct *product = _products[button.tag]; //[[rageiaphelper sharedinstance] buyproduct:product]; } }
here 2 pictures reference, give me hand!
uiview's tag not suitable passing information around, although see abuse lot.
save index path of selected cell , use when alert button fired. names on buttons not matter, give title.
Comments
Post a Comment