我想填充一个tableView与从SQLite数据库中提取的信息...我已经阅读了一些教程,并试图关注它们,但由于某种原因,我的应用程序不断崩溃。 ..iOS:从SQLite数据库填充tableView
.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
任何帮助将不胜感激...... 我知道我的数据库的作品,因为我能从中获取数据在其他地方,但似乎当我尝试在这里使用它,应用程序崩溃只是......
它的主要EXC_BAD_ACCESS和SIGABRT那得到的显示为错误...
现在,我已经告诉SIGABORT =“SIGABRT是程序尝试中止时发送的信号。通常这是因为发生了一些非常糟糕的事情。“
和”EXC_BAD_ACCESS发生在消息发送到已释放的对象时。通过捕捉错误时,调用堆栈通常特别是当处理多个线程不见了。”
好,伟大的..但我不如何解决它...任何帮助?
谢谢!似乎做的伎俩:) – user969043