so i've implemented mbprogresshud im trying line of code call makepost method boolean , if method posted correctly returns yes , if not no
[hud showwhileexecuting:@selector(makepost:) ontarget:self withobject:@"1" animated:yes]; if return value no i'd show alert
uialertview* cerror = [[uialertview alloc]initwithtitle:@"error try later!" message:@"post error" delegate:self cancelbuttontitle:nil otherbuttontitles:@"ok", nil]; [cerror show];
you can use method:
/** * shows hud while block executing on background queue, hides hud. */ - (void)showanimated:(bool)animated whileexecutingblock:(dispatch_block_t)block completionblock:(mbprogresshudcompletionblock)completion; follow comments in code:
- (ibaction)buttonclicked:(id)sender { // setup our alert use uialertcontroller instead of deprecated uialertview self.alertcontroller = [uialertcontroller alertcontrollerwithtitle: @"alert" message: @"hey ok ?" preferredstyle: uialertcontrollerstylealert]; // store result of method "makepost" lowercase ;) __block bool result; // setup hud mbprogresshud *hud = [mbprogresshud showhudaddedto:self.view animated:yes]; hud.mode = mbprogresshudmodeannulardeterminate; hud.labeltext = @"loading"; [hud showanimated:yes whileexecutingblock:^{ result = [self makepost]; } completionblock:^{ if (result) { nslog(@"ok"); } else { [self presentviewcontroller: self.alertcontroller animated: true completion: nil]; } }]; }
Comments
Post a Comment