J'essaie de remplir une tableView avec des informations extraites d'une base de données SQLite ... J'ai lu quelques tutoriels et essayé de les suivre, mais pour une raison quelconque, mon application se bloque constamment. ..iOS: remplissage tableView de base de données SQLite
.h
//
// InOrder.h
// AGKUnsten
//
// Created by Jonas Christensen on 7/12/11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface InOrder : UIViewController <UITableViewDelegate, UITableViewDataSource> {
NSArray *artworkInfo;
int rowsInDatabase;
}
.m
@property (nonatomic, retain) NSArray *artworkInfo;
@end
//
// InOrder.m
// AGKUnsten
//
// Created by Jonas Christensen on 7/12/11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import "InOrder.h"
#import "ArtworkView.h"
#import "PaintingInfo.h"
#import "PaintingDatabase.h"
@implementation InOrder
@synthesize artworkInfo;
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return rowsInDatabase;
//return [artworkInfo count]; //Tried to use this, but app just crashes when it reaches this line
}
-(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];
}
NSLog(@"test");//To see how far I get in the code - this is outputted
//Configure the cell
//APP CRASHES IF I TRY TO DO SOMETHING WITH MY DATABASE IN HERE
//cell.textLabel.text = [artworkInfo objectAtIndex:indexPath.row];//Tried this
//PaintingInfo *info = [artworkInfo objectAtIndex:indexPath.row];//Tried this
//cell.textLabel.text = info.artist;
//[[cell textLabel] setText:[artworkInfo objectAtIndex:[indexPath row]]];//Thread 1: Program received signal: "SIGABRT"
NSLog(@"test2");//Never reach here if I uncomment any of the above
return cell;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)dealloc
{
[super dealloc];
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
self.title = @"Værker";
artworkInfo = [[PaintingDatabase database] findAllArtists];
rowsInDatabase = [artworkInfo count];
NSLog(@"%d", rowsInDatabase);
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end
Toute aide serait grandement apprécié ... Je sais que mes travaux de base de données, comme je suis en mesure d'obtenir des données de celui-ci autre part, mais il semble que lorsque je tente de l'utiliser ici, l'application tombe en panne juste ...
Il est principalement EXC_BAD_ACCESS et SIGABRT qui se est affiché comme l'erreur ...
Maintenant, je l'ai été dit que SIGABORT = "SIGABRT est le signal envoyé lorsque le programme tente de s'annuler. Généralement c'est parce que quelque chose de vraiment mauvais est arrivé. "
et" EXC_BAD_ACCESS se produit lorsqu'un message est envoyé à un objet qui a déjà été libéré. Au moment où l'erreur est pris, la pile d'appel est généralement disparu surtout si le traitement avec plusieurs threads. »
Eh bien, grand .. mais je ne sais pas comment y remédier ... Toute aide ??
Merci! Semblait faire l'affaire :) – user969043