我有UIActionSheet。它显示数组中的标题。当我点击按钮时,什么都不会发生。我也使用了NSLog。但它没有显示任何东西。按钮标题从数组中显示。但只有点击不起作用
代码:
ActionSheet:
TSActionSheet *actionSheet = [[TSActionSheet alloc] initWithTitle:@"Design"];
for (int i = 0; i<[catearray count]; i++ ) {
[actionSheet addButtonWithTitle:[catearray objectAtIndex:i] block:^{
}];
}
按下按钮:
-(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) {
}
}
阵列:
if (sqlite3_open([path UTF8String], &database) == SQLITE_OK) {
const char *sql = "SELECT id,cat_name FROM categories";
NSLog(@"sql is %s",sql);
sqlite3_stmt *statement;
// int catID = 0;
if (sqlite3_prepare_v2(database, sql, -1, &statement, NULL) == SQLITE_OK) {
// We "step" through the results - once for each row.
while (sqlite3_step(statement) == SQLITE_ROW) {
category = [[NSString alloc] initWithUTF8String:
(const char *) sqlite3_column_text(statement, 1)];
NSLog(@"catName is %@",category);
[catearray addObject:category];
// catID = sqlite3_column_int(statement, 0);
}
}
sqlite3_finalize(statement);
}
else {
sqlite3_close(database);
NSAssert1(0, @"Failed to open database with message '%s'.", sqlite3_errmsg(database));
// Additional error handling, as appropriate...
}
答案 0 :(得分:1)
不,你没有使用UIActionSheet,你使用的是TSActionSheet,它不是UIActionSheet(It's a subclass of UIView)的子类,所以没有期望它实现UIActionSheetDelegate协议。请注意,向TSActionSheet添加按钮时,传递给按钮的参数之一是块。这是您在按下按钮时放置要执行的代码的位置。
[actionSheet addButtonWithTitle:@"button one" color:[UIColor whiteColor] titleColor:[UIColor darkGrayColor] borderWidth:1 borderColor:[UIColor grayColor] block:^{
NSLog(@"pushed button one");
}];
答案 1 :(得分:1)
您正在使用名为TSActionSheet的库和默认情况下未调用的操作UIActionSheetDelegate
所以你必须将你的行动转移到像这样的方法
-(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) {
}
}
然后像你这样在你的块上调用这个方法
TSActionSheet *actionSheet = [[TSActionSheet alloc] initWithTitle:@"Design"];
for (int i = 0; i<[catearray count]; i++ ) {
[actionSheet addButtonWithTitle:[catearray objectAtIndex:i] block:^{
[self actionSheetClickedButtonAtIndex:i];
}];
}