Calling the looped delegate only works the first time

Some background info

I’m making an app which has a adminsitration backend for updating it’s data. The app saves all data in an SQLite datbase for offline support. The backend has a simple API that returns new data in JSON depending on the applications latest synchronization date. The data contains images which is downloaded and saved in the app.

The problem

I have solved most of it but got stuck at this problem. When the data is loaded I loop through it and initiate the ImageHandler class which will download the image, save it and insert a row in the database. This works fine the first time but it doesn’t go past the first data row in the loop. If i uncomment the [imageHandler loadForPlace:row]; / [imageHandler loadForCategory:row]; rows the loop runs just fine. The ImageHandler class just checks if the image exists and downloads it if it doesn’t.

for (NSDictionary *row in data) {
    NSLog(@"Action: %@. Loading images...", [row objectForKey:@"action"]);

    imageHandler = [[Image alloc] init];
    imageHandler.delegate = self;

    if([[row objectForKey:@"action"] isEqualToString:@"CREATE_POST"] || [[row objectForKey:@"action"] isEqualToString:@"UPDATE_POST"]) {
        NSLog(@"1 (pre)");
        [imageHandler loadForPlace:row];
        NSLog(@"1");
    }
    else {
        NSLog(@"2 (pre)");
        [imageHandler loadForCategory:row];
        NSLog(@"2");
    }
}

Output:

2012-04-18 10:32:08.698 Appname[17636:11603] Syncronize: Request done
2012-04-18 10:32:08.698 Appname[17636:11603] Found 2 items to create or update.
2012-04-18 10:32:08.698 Appname[17636:11603] Action: CREATE_POST. Loading images...
2012-04-18 10:32:08.699 Appname[17636:11603] 1 (pre)
2012-04-18 10:32:08.699 Appname[17636:11603] id: 778
2012-04-18 10:32:08.700 Appname[17636:11603] Image already exists, continuing...
2012-04-18 10:32:08.700 Appname[17636:11603] Image(s) saved
2012-04-18 10:32:08.700 Appname[17636:11603] Create place
2012-04-18 10:32:08.701 Appname[17636:11603] Has image

loadForItem (called by loadForPlace and loadForCategory):

As you can see I commented out the delegate calls since they are the ones causing the loop not to continue. When I run this the loop continues without a problem. With my test data I currently end up in the “Image already exists, continuing…” part of loadForItem so it doesn’t do anything when the delegate code is commented out.

Edit:Okay, I don’t know why I haven’t noticed this before, but the application hangs withouth any errors outputed to the console. Damn! It’s when the delegate calls my method after checking the images that crashes this. That method inserts / updates the place in my sqlite database and I’m using fmdb which crashes my app without any errors. This has happened before when updating / inserting with fmdb.

Edit2:I have narrowed it down to this UPDATE query. It locks the whole application without any errors. [db executeUpdate:@"UPDATE categories SET number_places = 21 WHERE id = 44"];

Since NSLog(@"1 (pre)")
is evidently called, from the log output you provided, but NSLog(@"1")
is not, that suggests that -[Image loadForPlace:]
is not returning. You’ll have to look there for the cause.

Hello, buddy!责编内容来自:Hello, buddy! (源链) | 更多关于

阅读提示:酷辣虫无法对本内容的真实性提供任何保证,请自行验证并承担相关的风险与后果!
本站遵循[CC BY-NC-SA 4.0]。如您有版权、意见投诉等问题,请通过eMail联系我们处理。
酷辣虫 » 移动开发 » Calling the looped delegate only works the first time

喜欢 (0)or分享给?

专业 x 专注 x 聚合 x 分享 CC BY-NC-SA 4.0

使用声明 | 英豪名录