0
.h文件中EXC_BAD_ACCESS @synthesize
#import <UIKit/UIKit.h>
#import "Tardies.h"
#import "DBAccess.h"
@interface TardiesViewController : UITableViewController
<UITableViewDelegate, UITableViewDataSource, UIPrintInteractionControllerDelegate> {
NSMutableArray *tardiesAry;
UITableView *table;
}
@property (nonatomic, retain) NSMutableArray *tardiesAry;
@property (nonatomic, retain) IBOutlet UITableView *table;
@end
.m文件
#import "TardiesViewController.h"
@implementation TardiesViewController
@synthesize tardiesAry;
@synthesize table;
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
DBAccess *dbAccess = [[DBAccess alloc] init];
self.tardiesAry = [dbAccess getTardies];
[dbAccess closeDatabase];
[dbAccess release];
[table reloadData];
}
- (void)viewDidUnload {
[super viewDidUnload];
self.tardiesAry = nil;
}
- (void)dealloc {
[tardiesAry release];
}
@end
- (NSMutableArray *) getTardies
{
// [self deleteFromTardies:@""];
NSLog (@"DBAccess - getTardies - 1");
NSMutableArray *tardies = [[[NSMutableArray alloc] init] autorelease];
const char *sql = "SELECT tardies.studentId, tardyDate, tardyTime, lastName, firstName, middleName FROM tardies LEFT JOIN students ON tardies.studentId = students.studentId ORDER BY tardyDate desc, tardyTime desc, lastName, firstName, middleName";
sqlite3_stmt *statement;
int sqlResult = sqlite3_prepare_v2(database, sql, -1, &statement, NULL);
if (sqlResult == SQLITE_OK)
{
NSLog (@"DBAccess - getTardies - 6");
while (sqlite3_step(statement) == SQLITE_ROW)
{
Tardies *tardy = [[Tardies alloc] init];
char *stuId = (char *) sqlite3_column_text(statement, 0);
char *trdyDate = (char *) sqlite3_column_text(statement, 1);
char *trdyTime = (char *) sqlite3_column_text(statement, 2);
char *lName = (char *) sqlite3_column_text(statement, 3);
char *fName = (char *) sqlite3_column_text(statement, 4);
char *mName = (char *) sqlite3_column_text(statement, 5);
tardy.studentId = (stuId) ? [NSString stringWithUTF8String:stuId] : @" ";
tardy.tardyDate = (trdyDate) ? [NSString stringWithUTF8String:trdyDate] : @" ";
tardy.tardyTime = (trdyTime) ? [NSString stringWithUTF8String:trdyTime] : @" ";
NSString *lNm = (lName) ? [NSString stringWithUTF8String:lName] : @" ";
NSString *fNm = (fName) ? [NSString stringWithUTF8String:fName] : @" ";
NSString *mNm = (mName) ? [NSString stringWithUTF8String:mName] : @" ";
tardy.fullName = [NSString stringWithFormat:@"%@, %@ %@", lNm, fNm, mNm];
NSDictionary *tardyDict = [[NSDictionary alloc] initWithObjectsAndKeys:tardy.studentId, @"studentId",
tardy.tardyDate, @"tardyDate",
tardy.tardyTime, @"tardyTime",
tardy.fullName, @"fullName",
nil];
[tardies addObject:tardyDict];
[tardy release];
[tardyDict release];
}
// Finalize the statement to release its resources
sqlite3_finalize(statement);
}
else
{
NSLog (@"Problem with the database:");
NSLog (@"%d", sqlResult);
}
return tardies;
}
- (void) closeDatabase
{
// Close the database
if (sqlite3_close(database) != SQLITE_OK)
{
// NSAssert1(0, @"Error: failed to close database: '%s' .", sqlite3_errmsg(database));
}
}
的Xcode 4.0版編譯4A304a
第一次setTardiesAry運行,它是好的,第二這時,程序上錯誤的@synthesize tardiesAry行失敗: 線程1:程序接收到的信號「EXC_BAD_ACCESS」。
我試圖重寫方法setTardiesAry,未能在該方法而不是@synthesize行模式。
請幫幫忙,我不知道如何繼續。
有人曾在getTardies自動釋放。
最有可能通過返回的數組'[DBACCESS getTardies]'包含發佈過多次的對象。請發佈該方法的代碼。 – Anomie 2011-03-24 22:30:21
看起來像你的DBAccess類中的東西被過度釋放。 – Rog 2011-03-24 22:31:40
而@Anomie打我衝 – Rog 2011-03-24 22:32:19