ios - Link UITableView delegate function back to other function -


i've created custom alert method, uitableview inside it.

typedef void (^succes)(id data); typedef void (^failure)(nserror *error);  + (void)testfortable:(nsstring *)title withsuccess:(succes)success failure:(failure)failure {     sclalertview *alert = [[sclalertview alloc] initwithnewwindow];     alert.customviewcolor = [uicolor papercolorlightblue500];     [alert setshowanimationtype:slideinfromright];     uitableview *tableview = [alert addtableview];     tableview.delegate = self;     tableview.datasource = self;      [alert showedit:self title:@"test table"                 subtitle:@"this test alert table"         closebuttontitle:nil duration:0.0f]; }  #pragma mark - tableview methods + (cgfloat)tableview:(uitableview *)tableview heightforrowatindexpath:(nsindexpath *)indexpath{     return 40;  }  + (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section {     return 20; }  + (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath {     uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:@"cell"];     if(cell == nil) cell = [[uitableviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:@"cell"];      cell.accessorytype = uitableviewcellaccessorydisclosureindicator;     cell.textlabel.text = [nsstring stringwithformat:@"%d", indexpath.row];      return cell; }  + (void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath {     nslog(@"%d", indexpath.row); } 

now, ideally, when user touches uitableviewcell, i'd indexpath.row passed success parameter of testfortable. how can this? possible?

sclalertview should delegate of uitableview, can handle didselectrowatindexpath:.

seeing datasource simple, sclalertview datasource.

so:

tableview.delegate = alert; tableview.datasource = alert; 

then move delegate implementation sclalertview.

edit

i don't know kind of object success is, if it's block, keep reference of on uiviewcontroller , call when didselectrowatindexpath: too.

edit 2

your success block need accept nsinteger parameter:

typedef void (^success)(id data, nsinteger row); 

and call on delegate:

+ (void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath {     id data; //this data placeholder, dont know how this.     if (self.success) {         self.success(data, indexpath.row);     } } 

you hold reference of success block on delegate

@property (nonatomic, copy) success success; 

Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -