I am sure this is an issue with my iOS/ObjC noob-ness...
I have a UITableView with entries in, when the user selects a row,
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
...
[self.twitter sendUpdate:[self getTweet]];
and
- (NSString *)sendUpdate:(NSString *)text;
{
NSLog(@"showing HUD");
self.progressSheet = [MBProgressHUD showHUDAddedTo:[[UIApplication sharedApplication] keyWindow] animated:YES];
self.progressSheet.labelText = @"Working:";
self.progressSheet.detailsLabelText = text;
// Build a twitter request
TWRequest *postRequest = [[TWRequest alloc] initWithURL:
[NSURL URLWithString:@"http://api.twitter.com/1/statuses/update.json"]
parameters:[NSDictionary dictionaryWithObject:text
forKey:@"status"] requestMethod:TWRequestMethodPOST];
// Post the request
[postRequest setAccount:self.twitterAccount];
// Block handler to manage the response
[postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error)
{
NSLog(@"Twitter response, HTTP response: %i", [urlResponse statusCode]);
NSLog(@"hiding HUD");
[MBProgressHUD hideHUDForView:[[UIApplication sharedApplication] keyWindow] animated:YES];
self.progressSheet = nil;
It calls the builtin Twitter api to send a tweet. I am using MBProgressHUD while the sending is going on. I am getting erratic behaviour with the HUD disappearance, generally it hangs around 10 or so seconds longer than it should. Based on the show/hide logging I am seeing.
I have another, simpler view, which just lists tweets and that uses the HUD with no problem - although its done via the viewWillAppear call.
Perhaps I need to do the showing via another thread?
Thanks in advance for any thoughts ~chris
Yes, you are right about ui thread. You can also write this:
dispatch_async(dispatch_get_main_queue(), ^{
[self.progressSheet hide:YES];
self.progressSheet = nil;
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With