iPhone Apps를 시험하고 있는데 C#에서 왔습니다. iPhone 개발 환경을 파악하기가 매우 어렵습니다.Sqlite를 사용하여 iPhone App에서 세부 정보보기를 표시하는 방법
지금까지 TableViewController에 'Makes'를 나열 할 수있었습니다. 나는 이제 Makes가 선택되었을 때 열거 된 'Models'에 들기를 원합니다. 샘플 코드를 누군가 도와 줄 수 있습니까?
동일한 TableViewController를 사용하여 자동차 모델을 표시 할 수 있습니까?
코드를 만들지 않았으므로 코드에서 모두 수행하고 있습니다.
자세한 내용은 다음과 같습니다. select title from make where parentkey =? 상위 키는 make의 기본 키입니다.
// MakeListTableViewController.h
#import <UIKit/UIKit.h>
#import "ModelTableViewController.h"
@interface MakeListTableViewController : UITableViewController {
NSMutableArray *makes;
ModelTableViewController *modelTableViewController;
UITabBarController *tabBarController;
}
@property (nonatomic, retain) ModelTableViewController * modelTableViewController;
@property (nonatomic, retain) UITabBarController *tabBarController;
@end
// MakeListTableViewController.m
#import "MakeListTableViewController.h"
#import "ModelTableViewController.h"
#import "sqlite3.h"
static int MyCallback(void *context, int count, char **values, char **columns)
{
NSMutableArray *categories = (NSMutableArray *)context;
for (int i=0; i < count; i++) {
const char *titleCString = values[i];
[makes addObject:[NSString stringWithUTF8String:titleCString]];
}
return SQLITE_OK;
}
@implementation MakeListTableViewController
- (void)loadNamesFromDatabase
{
NSString *file = [[NSBundle mainBundle] pathForResource:@"CarList" ofType:@"sqlite"];
sqlite3 *database = NULL;
if (sqlite3_open([file UTF8String], &database) == SQLITE_OK) {
sqlite3_exec(database, "select title from make where parentkey = 0", MyCallback, makes, NULL);
}
sqlite3_close(database);
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
//return 0;
return [makes count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// THIS IS WHERE I THINK THE INDEX IS PASSED ON FOR THE DETAILS
UITableViewCell *cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:nil] autorelease];
cell.text = [makes objectAtIndex:indexPath.row];
//return cell;
return [cell autorelease];
}
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
makes = [[NSMutableArray alloc] init];
[self loadNamesFromDatabase];
}
return self;
}
- (void)dealloc {
[makes release];
[super dealloc];
}
@end
SQL
내 C# 프로그램에서CREATE TABLE make(pk INTEGER PRIMARY KEY, parentkey INTEGER DEFAULT 0, title TEXT);
INSERT INTO make(title) VALUES('Honda');
INSERT INTO make(title) VALUES('Toyota');
INSERT INTO make(title) VALUES('Mazda');
INSERT INTO make(title) VALUES('Nissan');
INSERT INTO make(title, parentkey) VALUES('Civic', 1);
INSERT INTO make(title, parentkey) VALUES('Accord', 1);
INSERT INTO make(title, parentkey) VALUES('Corolla', 2);
I가의 GridView 같은 세부 기록을 얻을 수있는 기본 키를 사용하여 사용하고, 그것은 또한 아이폰에서 수행하는 방법이 무엇입니까?