开发者

Problem while scrolling Table View

I have the following problem while i scroll the table view:

NSCFString objectAtIndex:]: unrecognized selector sent to instance

I create NSDictionary tableContents and when i scroll it becomes deallocated. This is my code:

- (void)viewDidLoad {

lessonsInGroup1 = [NSMutableArray array];
lessonsInGroup2 = [NSMutableArray array];
lessonsInGroup1 = [self grabRowsInGroup:@"1"];
lessonsInGroup2 = [self grabRowsInGroup:@"2"];

NSDictionary *temp =[[NSDictionary alloc]initWithObjectsAndKeys:lessonsInGroup1,@"General Information",lessonsInGroup2,@"LaTeX Examples", nil];
//[[tableContents alloc] init];
self.tableContents =temp;
[temp release];
NSLog(@"table %@",self.tableContents);
NSLog(@"table with Keys %@",[self.tableContents allKeys]);

self.sortedKeys =[[self.tableContents allKeys] sortedArrayUsingSelector:@selector(compare:)];
NSLog(@"sorted %@",self.sortedKeys);

[lessonsInGroup1 release];
[lessonsInGroup2 release];

//[table reloadData];
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem开发者_Python百科 = self.editButtonItem;

[super viewDidLoad];

}

- (NSMutableArray *) grabRowsInGroup:(NSString*)GroupID{

NSMutableArray *groupOfLessons; 
groupOfLessons = [[NSMutableArray alloc] init];
char *sqlStatement;
int returnCode;
sqlite3_stmt *statement;
NSString *databaseName;
NSString *databasePath;

// Setup some globals
databaseName = @"TexDatabase.sql";

// Get the path to the documents directory and append the databaseName
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [documentPaths objectAtIndex:0];
databasePath = [documentsDir stringByAppendingPathComponent:databaseName];

// Setup the database object
sqlite3 *database;

// Open the database from the users filessytem
if(sqlite3_open([databasePath UTF8String], &database) != SQLITE_OK) {
    fprintf(stderr, "Error in opening the database. Error: %s",
            sqlite3_errmsg(database));
    sqlite3_close(database);
    return;
}
sqlStatement = sqlite3_mprintf(
                               "SELECT * FROM Lessons WHERE LessonGroup = '%s';", [GroupID UTF8String]);

returnCode =
sqlite3_prepare_v2(database,
                   sqlStatement, strlen(sqlStatement),
                   &statement, NULL);
if(returnCode != SQLITE_OK) {
    fprintf(stderr, "Error in preparation of query. Error: %s",
            sqlite3_errmsg(database));
    sqlite3_close(database);
    return;
}
returnCode = sqlite3_step(statement);
while(returnCode == SQLITE_ROW) {

    NSString *aLessonID = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 0)];
    NSString *aLessonGroup = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 1)];
    NSString *aLessonTopic = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 2)];
    NSString *aLessonText = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 3)];
    NSString *aLessonCode = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 4)];
    NSString *aLessonPicture = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 5)];

    /*NSLog(aLessonID);
    NSLog(aLessonGroup);
    NSLog(aLessonTopic);
    NSLog(aLessonText);
    NSLog(aLessonCode);
    NSLog(aLessonPicture);*/

    // Create a new busCit object with the data from the database
    Lesson *lesson = [[Lesson alloc] initWithLessonID:aLessonID LessonGroup:aLessonGroup LessonTopic:aLessonTopic LessonText:aLessonText LessonCode:aLessonCode LessonPicture:aLessonPicture];

    [groupOfLessons addObject:lesson];

    returnCode = sqlite3_step(statement);
}
sqlite3_finalize(statement);
sqlite3_free(sqlStatement);

return [groupOfLessons autorelease];

}


What does your @property for tableofContents look like?

Also, you are going to run into issues with

[lessonsInGroup1 release];
[lessonsInGroup2 release];

because you are autoreleasing those in the grabRowsInGroup:

So, you don't need to call release them.


Looks like you are calling objectAtIndex on NSString. It should rather be some array

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜