iphone - UIActionSheet button is not working -
i have uiactionsheet. displays title array. when click button nothing happen. used nslog also. it's not displaying anything. button title displaying array. click not working
code:
actionsheet:
tsactionsheet *actionsheet = [[tsactionsheet alloc] initwithtitle:@"design"]; (int = 0; i<[catearray count]; i++ ) { [actionsheet addbuttonwithtitle:[catearray objectatindex:i] block:^{ }]; }
button click:
-(void)actionsheet:(uiactionsheet *)actionsheet clickedbuttonatindex:(nsinteger)buttonindex { if (buttonindex == 0) { nslog(@"button"); } else if (buttonindex == 1) { nslog(@"button 1"); } else if (buttonindex == 2) { nslog(@"button 2"); } else if (buttonindex == 3) { } }
array:
if (sqlite3_open([path utf8string], &database) == sqlite_ok) { const char *sql = "select id,cat_name categories"; nslog(@"sql %s",sql); sqlite3_stmt *statement; // int catid = 0; if (sqlite3_prepare_v2(database, sql, -1, &statement, null) == sqlite_ok) { // "step" through results - once each row. while (sqlite3_step(statement) == sqlite_row) { category = [[nsstring alloc] initwithutf8string: (const char *) sqlite3_column_text(statement, 1)]; nslog(@"catname %@",category); [catearray addobject:category]; // catid = sqlite3_column_int(statement, 0); } } sqlite3_finalize(statement); } else { sqlite3_close(database); nsassert1(0, @"failed open database message '%s'.", sqlite3_errmsg(database)); // additional error handling, appropriate... }
you using library called tsactionsheet , actions not called in default uiactionsheetdelegate
so u have to move action method this
-(void)actionsheetclickedbuttonatindex:(int)buttonindex { if (buttonindex == 0) { nslog(@"button"); } else if (buttonindex == 1) { nslog(@"button 1"); } else if (buttonindex == 2) { nslog(@"button 2"); } else if (buttonindex == 3) { } }
then call method on block this
tsactionsheet *actionsheet = [[tsactionsheet alloc] initwithtitle:@"design"]; (int = 0; i<[catearray count]; i++ ) { [actionsheet addbuttonwithtitle:[catearray objectatindex:i] block:^{ [self actionsheetclickedbuttonatindex:i]; }]; }
Comments
Post a Comment