0

In my application I have a table view in second view controller. After some time I display an alert view using timer on which I have two buttons yes and no. When I click yes the alert view gets dismissed and when I click the no it should delete all items in table view and reload it.

Problem

I am not able to refresh the table view when I go to first view controller and return to second view controller.If I am in same view controller, it reloads perfectly.

Timer function

start_Timer = [NSTimer scheduledTimerWithTimeInterval:30 target:self selector:@selector(start_method) userInfo:nil repeats:NO];

Alert show

 -(void)start_method
    {
           Timerfunction_alert = [[UIAlertView alloc] initWithTitle:@"" message:@"You have less than one minute before all items on your order list are released as it is about to exceed the 15-minutes hold time allocated to you to complete your order. Do you wish to continue ordering this item?" 
                                                           delegate:self 
                                                  cancelButtonTitle:@"NO" 
                                                  otherButtonTitles:@"YES", nil];
     [Timerfunction_alert show];
    }



 - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
 {
      if (alertView == Timerfunction_alert)
       {
         if (buttonIndex == 0)
          {
            //here to refresh the table view
           [self.tableview reloaddata]
         }
      }
 }
4

3 回答 3

0

尝试这个:

[self performSelector:@selector(start_method) withObject:nil afterDelay:30];
于 2013-06-11T15:26:45.733 回答
0
[NSTimer scheduledTimerWithTimeInterval:30 target:self selector:@selector(start_method) userInfo:nil repeats:YES];

-(void)start_method
{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"You have less than one minute before all items on your order list are released as it is about to exceed the 15-minutes hold time allocated to you to complete your order. Do you wish to continue ordering this item?" delegate:self cancelButtonTitle:@"NO" otherButtonTitles:@"YES", nil];
    alert.tag=1;
    [alert show];
    [alert release];
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (alertView.tag==1)
    {
        if (buttonIndex == 1)
        {
            //here to refresh the table view
            [self.tableview reloaddata]
        }
    }
}
于 2013-06-12T05:32:33.120 回答
0

我的经验告诉我,你应该遵循这个片段

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
 {
      if (alertView == paymentalert)
       {
         if (buttonIndex == 0)
          {
// reload table after main thread gets over, sothat app doesn't crash
    [self performSelectorOnMainThread:@selector(ReloadTable) withObject:nil waitUntilDone:YES];

         }
      }
 }

//here to refresh the table view
-(void)ReloadTable
{
           [self.tableview reloaddata]
}
于 2013-06-12T05:29:44.110 回答