Ich probiere iPhone Apps aus C#, finde ich sehr schwierig, die iPhone-dev-Umgebung zu erfassen.Wie zeige ich Details Ansicht in iPhone App mit Sqlite
Bis jetzt kann ich meine 'Makes' in einem TableViewController aufgelistet bekommen. Ich möchte jetzt, Modelle 'aufgelistet bekommen, wenn ein Makes ausgewählt ist. Kann mir jemand mit Beispielcode helfen.
Kann ich den gleichen TableViewController verwenden, um die Modelle der Autos anzuzeigen?
Ich habe keine Nibs erstellt, ich mache alles in Code.
Die Sql für die Details wäre: Wählen Sie Titel von machen, wo Parentkey =? Der Parentkey ist der Primärschlüssel der Marke.
// 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
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);
In meiner C# -Programme Ich bin es gewohnt, den Primärschlüssel mit dem Detail aufnehmen, wie das Gridview zu bekommen, ist dies, wie es auch im iPhone gemacht wird?