Objective c 从sqlite到tableview
我对objective-c很陌生,所以我有几个问题。Objective c 从sqlite到tableview,objective-c,sqlite,tableview,Objective C,Sqlite,Tableview,我对objective-c很陌生,所以我有几个问题。 如何从(SQLite)数据库中获取数据以显示在表视图中。实际上,我现在可以从表中选择数据,但我真的不知道如何将数据库表中的项目名称添加到我的tableview中 在第一个问题之后,如何单击根据第一个问题命名的tableview单元格,然后移动到另一个控制器,该控制器在该视图上显示项目的名称和说明 在我的loaddata方法中,我已经可以调用并从表中选择项目,并将其显示在NSLog上 你们能告诉我怎么做吗,或者给我一些教程或链接,我可以看看并进
请找到问题的答案
//Get the details from SQLLite DB
[self performSegueWithIdentifier:@"segue identifier" sender:self];
}
(void)prepareForSegue:(UIStoryboardSegue*)segue发送方:(id)发送方
{
if([segue.identifier IsequalString:@“segue identifier”])
{
UIViewController*控制器=(UIViewController*)segue.destinationViewController;
}
}希望这有帮助。例如,我认为您需要这样的方法。
TableViewController⇔ 详细数据控制器 NSObject*数据
@property NSInteger dataId;
@pproperty NSString* title;
视图控制器
- (NSArray *)arr
{
FMDatabase* db = [self getConnection];
[db open];
FMResultSet* results = [db executeQuery:SQL_SELECT];
NSMutableArray* books = [[NSMutableArray alloc] initWithCapacity:0];
while( [results next] )
{
Data* data = [[Book alloc] init];
data.dataId = [results intForColumnIndex:0];
data.title = [results stringForColumnIndex:1];
[arr addObject:data];
}
[db close];
return arr;
}
- (Data*)dataAtIndexPath:(NSIndexPath*)indexPath
{
return [arr objectAtIndex:indexPath.row];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//cellIdentifier etc
Data* data = [self dataAtIndexPath:indexPath];
cell.textLabel.text = data.title;
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
DetailDataController* detail = [[DetailDataController alloc] initWithNibName:@"DetailData" bundle:nil];
detail.delegate = self;
detail.data = [self dataAtIndexPath:indexPath];
[self.navigationController pushViewController:detail animated:YES];
}
- (NSArray *)arr
{
FMDatabase* db = [self getConnection];
[db open];
FMResultSet* results = [db executeQuery:SQL_SELECT];
NSMutableArray* books = [[NSMutableArray alloc] initWithCapacity:0];
while( [results next] )
{
Data* data = [[Book alloc] init];
data.dataId = [results intForColumnIndex:0];
data.title = [results stringForColumnIndex:1];
[arr addObject:data];
}
[db close];
return arr;
}
- (Data*)dataAtIndexPath:(NSIndexPath*)indexPath
{
return [arr objectAtIndex:indexPath.row];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//cellIdentifier etc
Data* data = [self dataAtIndexPath:indexPath];
cell.textLabel.text = data.title;
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
DetailDataController* detail = [[DetailDataController alloc] initWithNibName:@"DetailData" bundle:nil];
detail.delegate = self;
detail.data = [self dataAtIndexPath:indexPath];
[self.navigationController pushViewController:detail animated:YES];
}