I have been getting this error and have no idea how to fix it. I am a newbie for iOS programming.
Hope the codes below is enough to see what the problem is.
Here is my ListTableController.m
...
@implementation ListTableController
@synthesize listTableView;
@synthesize detailController;
@synthesize listOfTasks;
@synthesize title, note, date;
-(id)initWithTitle:(NSString *)sTitle note:(NSString *)sNote date:(NSString *)sDate {
NSLog(@"FUNC: %s",__FUNCTION__);
self.title = sTitle;
self.note = sNote;
self.date = sDate;
return self;
}
// Retrieve records
-(void) getAllRowsFromTableNamed: (NSString *) tableName {
//---retrieve rows---
NSString *qsql = [NSString stringWithFormat:@"SELECT 开发者_如何学JAVA* FROM %@ WHERE status = '1' ORDER BY date ASC",tableName]; sqlite3_stmt *statement;
//---initialize the array---
listOfTasks = [[NSMutableArray alloc] init];
if (sqlite3_prepare_v2( db, [qsql UTF8String], -1, &statement, nil) == SQLITE_OK) {
while (sqlite3_step(statement) == SQLITE_ROW) {
NSString *fieldTitle = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 1)];
NSString *fieldNote = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 2)];
NSString *fieldDate = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 3)];
// Create a new object with the data from the database
NSString *str = [[NSString alloc] initWithTitle :fieldTitle note:fieldNote date:fieldDate];
[listOfTasks addObject:str];
[str release];
[fieldTitle release];
[fieldNote release];
[fieldDate release];
}
//---deletes the compiled statement from memory---
sqlite3_finalize(statement);
}
}
...
Here is my ListTableController.h
#import
#import "sqlite3.h"
#import "TaskDetailController.h"
@interface ListTableController : UITableViewController {
IBOutlet UITableView *listTableView;
sqlite3 *db;
TaskDetailController *detailController;
}
NSString *title;
NSString *note;
NSString *date;
NSMutableArray * listOfTasks;
@property (nonatomic, retain) NSString *title;
@property (nonatomic, retain) NSString *note;
@property (nonatomic, retain) NSString *date;
@property (nonatomic, retain) TaskDetailController *detailController;
@property (nonatomic, retain) IBOutlet UITableView *listTableView;
@property (nonatomic, retain) NSMutableArray *listOfTasks;
-(void) copyDatabaseIfNeeded;
-(NSString *) filePath;
-(IBAction)addCalendar;
-(NSInteger)countToday;
-(id)initWithTitle:(NSString *)sTitle note:(NSString *)sNote date:(NSString *)sDate;
@end
And this is the error log from the console:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSPlaceholderString initWithTitle:note:date:]: unrecognized selector sent to instance 0x4e00470'
Try removing these lines. Class methods as [NSString stringWith.... returns autoreleased objects.
[fieldTitle release];
[fieldNote release];
[fieldDate release];
I think you have to learn about memory management first. You will get a big headache if you don't.
Try removing these lines.
[fieldTitle release]; [fieldNote release]; [fieldDate release];
And if you want to combine title , note , and date as a single line.
then try this
// Create a new object with the data from the database NSString *str = [[NSString stringWithFormate:@"%@ %@ %@",fieldTitle,fieldNote,fieldDate];
instead of
// Create a new object with the data from the database NSString *str = [[NSString alloc] initWithTitle :fieldTitle note:fieldNote date:fieldDate];
精彩评论