我有带有用户名和密码的登录页面。当我输入正确的凭据时,它将转到另一个视图控制器。在这个视图控制器中,我有按钮来单击匹配的用户信息。如果用户名匹配,我只需要检索他们的数据并显示。
代码:
视图控制器.m:
if ([responseData length]){
NSLog(@"Response ==> %@", responseData);
NSMutableDictionary *dict=[responseData JSONValue];
NSMutableDictionary *dict1=[responseData JSONValue];
NSInteger success = [(NSNumber *) [dict objectForKey:@"success"] integerValue];
NSInteger id1 = [(NSNumber *) [dict1 objectForKey:@"id"] integerValue];
NSLog(@"%d",success);
if(success == 1){
NSLog(@"Login SUCCESS");
[self alertStatus:@"Logged in Successfully." :@"Login Success!"];
[self.navigationController pushViewController:overlay animated:YES];
} else {
NSString *error_msg = (NSString *) [dict objectForKey:@"error_message"];
[self alertStatus:error_msg :@"Login Failed!"];
}
}
上面的代码objForKey=@"success"
包含username & password.
ObjForKey=@"id"
包含每个用户 ID。如果此 id 匹配,我需要显示该 id 数据。
viewController1.m:
在这里我需要得到ObjForKey=@"id"
。company_id 存储ObjForKey=@"id"
数据。如何在选择查询中传递ObjForKey=@"id"
from viewController
to 。&包含特定用户产品名称和 ID 的数组。如果匹配,我需要获取该用户&ViewController1.m
CategoryNames
categoryIds
ObjForKey=@"id"
categoryNames
categoryIds
if (sqlite3_open([path UTF8String], &database) == SQLITE_OK) {
const char *sql = "SELECT id,cat_name FROM categories where company_id = ObjForKey=@"id";
NSLog(@"sql is %s",sql);
categoryNames = [NSMutableArray array];
categoryIds = [NSMutableArray array];
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) {
NSString *categoryName = [[NSString alloc]
initWithUTF8String:(const char *) sqlite3_column_text(statement, 1)];
NSLog(@"catName is %@",categoryName);
NSInteger categoryId = sqlite3_column_int(statement, 0);
[categoryNames addObject:categoryName];
[categoryIds addObject:@(categoryId)];
}
}
}
这里 UIActionSheet 显示特定用户 ID 的 categoryNames:
TSActionSheet *actionSheet = [[TSActionSheet alloc] initWithTitle:@"Design"];
for (int i = 0; i<[categoryNames count]; i++ ) {
NSLog(@"catearray is %@",categoryNames);
[actionSheet addButtonWithTitle:[categoryNames objectAtIndex:i] block:^{
[self actionSheetClickedButtonAtIndex:i];
}];