Tableview没有从alertview刷新?

时间:2013-06-11 15:16:28

标签: iphone ios

在我的应用程序中,我在第二个视图控制器中有一个表视图。一段时间后,我使用计时器显示一个警报视图,我有两个按钮是和否。单击“是”时,警报视图将被取消,当我单击“否”时,应删除表视图中的所有项目并重新加载。

问题

当我转到第一个视图控制器并返回到第二个视图控制器时,我无法刷新表视图。如果我在同一个视图控制器中,它会重新加载。

计时器功能

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

提示节目

 -(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]
         }
      }
 }

3 个答案:

答案 0 :(得分:0)

试试这个:

[self performSelector:@selector(start_method) withObject:nil afterDelay:30];

答案 1 :(得分: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]
}

答案 2 :(得分: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]
        }
    }
}