iOS – Restkit makes UI no response

I am using RestKit version 0.2, and when I call RKRequestOperation, I see that it blocks the UI (meaning, the UI becomes incoherent/unresponsive), as shown below: < p>

- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset {
NSString *urlString = [NSString stringWithFormat:@"http://localhost:8080/models?offset=%d&rows=%d", _offset, _numRows];
NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
RKObjectRequestOperation *operation = [[RKObjectRequestOperation alloc] initWithRequest:request responseDescriptors:@[_responseDescriptor]];
[operation setCompletionBlockWithSuccess:^(RKObjectRequestOperation *operation, RKMappingResult * result) {
NSLog(@"Got models: %@", [result array]);
[self addModelsToView:[results array]];
} failure:^(RKObjectRequestOperation *operation , NSError *error) {
NSLog(@"FAIL ED!");
}];

[operation start];
}

More background:

I’m like this Doing this is to load the new model view into the infinite UIScrollView. I detected that when the user scrolled to the bottom of the view (coordinate logic editing), I used the RestKit above to load the next set of views, and when the model returned, I loaded them into addModelsToView’s scroll view. Even if I comment out addModelsToView, the logic of fluctuations still exists, so I’m sure it has something to do with RestKit (or at least how I use it).

According to my understanding of RestKit, it does It is loaded asynchronously, so I cannot find the reason/the reason for the fluctuation.

Thanks in advance!

calling start on NSOperation will start the synchronization operation on the same thread where you called it. So You perform this download on the main thread, which will prevent UI updates

You should add the operation to the queue

The RestKit github page has this example:

RKObjectManager *manager = [RKObjectManager managerWithBaseURL:[NSURL URLWithString:@"http://restkit.org"];

NSURLRequest *request = [NSURLRequest requestWithURL: [NSURL URLWithString:@"http://restkit.org/articles/1234.json"]];
RKObjectRequestOperation *operation = [[RKObjectRequestOperation alloc] initWithRequest:request responseDescriptors:@[responseDescriptor]];

[manager enqueueObjectRequestOperation:operation];

I am using RestKit version 0.2, when I call RKRequestOperation, I see that it blocks the UI (meaning ,UI becomes incoherent/unresponsive), as shown below:

- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset :(inout CGPoint *)targetContentOffset {
NSString *urlString = [NSString stringWithFormat:@"http://localhost:8080/mode ls?offset=%d&rows=%d", _offset, _numRows];
NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
RKObjectRequestOperation *operation = [[RKObjectRequestOperation alloc] initWithRequest:request responseDescriptors:@[_responseDescriptor]];
[operation setCompletionBlockWithSuccess:^(RKObjectRequestOperation *operation, RKMappingResult *result) {
NSLog(@"Got models: %@", [result array]);
[self addModelsToView:[results array]];
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
NSLog(@" FAILED!");
}];

[operation start];
}

More background:

I’m like this Doing this is to load the new model view into the infinite UIScrollView. I detected that when the user scrolled to the bottom of the view (coordinate logic editing), I used the RestKit above to load the next set of views, and when the model returned, I loaded them into addModelsToView’s scroll view. Even if I comment out addModelsToView, the logic of fluctuations still exists, so I’m sure it has something to do with RestKit (or at least how I use it).

According to my understanding of RestKit, it does It is loaded asynchronously, so I cannot find the reason/the reason for the fluctuation.

Thanks in advance!

Calling start on NSOperation will start the synchronization operation on the same thread where you called it. So you perform this download on the main thread, which will prevent UI update

You should add the operation to the queue

The RestKit github page has this example:

RKObjectManager * manager = [RKObjectManager managerWithBaseURL:[NSURL URLWithString:@"http://restkit.org"];

NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://restkit. org/articles/1234.json"]];
RKObjectRequestOperation *operation = [[RKObjectRequestOperation alloc] initWithRequest:request responseDescriptors:@[responseDescriptor]];

[manager enqueueObjectRequestOperation:operation];

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 3878 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.