ich habe den nachfolgenden controller in meinem projekt. wenn ich ihn aufrufe und das feste array aus der viewdidload verwende, wird der tableview angezeigt.
verwende ich aber die methode zum einlesen der daten stürzt die app ab. die daten sind aber im array drin, er zeigt mir bei numberOfRowsInSection die richtige anzahl der datensätze an.
woran kann das liegen?
Alles anzeigen
verwende ich aber die methode zum einlesen der daten stürzt die app ab. die daten sind aber im array drin, er zeigt mir bei numberOfRowsInSection die richtige anzahl der datensätze an.
woran kann das liegen?
Quellcode
- #import "FaelligVC.h"
- @interface FaelligVC ()
- @end
- @implementation FaelligVC
- - (id)initWithStyle:(UITableViewStyle)style
- {
- self = [super initWithStyle:style];
- if (self) {
- // Custom initialization
- }
- return self;
- }
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- // listOfItems = [[NSMutableArray alloc] init];
- listOfItems = [[NSMutableArray alloc] initWithObjects:@"Januar", @"Februar", @"März", @"April", @"Mai", @"Juni", @"Juli", @"August", @"September", @"Oktober", @"November", @"Dezember", nil];
- // [self datenlesen1];
- }
- - (void)viewDidUnload
- {
- [super viewDidUnload];
- // Release any retained subviews of the main view.
- // e.g. self.myOutlet = nil;
- }
- - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
- {
- return (interfaceOrientation == UIInterfaceOrientationPortrait);
- }
- #pragma mark - Table view data source
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- {
- // Return the number of sections.
- return 1;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- // Return the number of rows in the section.
- NSLog(@"%i",[listOfItems count]);
- return [listOfItems count];
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- static NSString *CellIdentifier = @"Cell";
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
- if (cell == nil) {
- cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
- }
- // Configure the cell...
- cell.textLabel.text = [listOfItems objectAtIndex:indexPath.row];
- return cell;
- }
- #pragma mark - Table view delegate
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
- // Navigation logic may go here. Create and push another view controller.
- /*
- <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
- // ...
- // Pass the selected object to the new view controller.
- [self.navigationController pushViewController:detailViewController animated:YES];
- [detailViewController release];
- */
- }
- -(void)datenlesen1 {
- NSString *databasePath = [[NSBundle mainBundle] pathForResource:@"faellig" ofType:@"sqlite"];
- const char *dbpath = [databasePath UTF8String];
- sqlite3_stmt *statement;
- NSString *abfrageSQL = nil;
- if (sqlite3_open(dbpath, &faelligDB) == SQLITE_OK) {
- abfrageSQL = [NSString stringWithFormat:@"SELECT * FROM daten ORDER BY datum, was"];
- const char *abfrage_stmt = [abfrageSQL UTF8String];
- if (sqlite3_prepare_v2(faelligDB, abfrage_stmt, -1, &statement, NULL) == SQLITE_OK) {
- while (sqlite3_step(statement) == SQLITE_ROW) {
- // Datum
- char *db_datum = (char *)sqlite3_column_text(statement, 2);
- if (db_datum == NULL) db_datum = "";
- NSString *value_datum = [NSString stringWithUTF8String:db_datum];
- // Was
- char *db_was = (char *)sqlite3_column_text(statement, 3);
- if (db_was == NULL) db_was = "";
- NSString *value_was = [NSString stringWithUTF8String:db_was];
- NSString *item;
- item = [NSString stringWithFormat:@" %@ %@",value_datum, value_was];
- [listOfItems addObject:value_datum];
- // NSLog(@"%i %@", [listOfItems count], item);
- } // ENDE WHILE
- } // ENDE IF
- } // ENDE IF
- sqlite3_close(faelligDB);
- [databasePath release];
- } // ENDE DATENLESEN
- @end
