NSTimer的奇怪错误(我相信)

时间:2011-09-14 16:27:54

标签: ios cocoa-touch nstimer void

我正在创建一个应用程序,我使用NSTimer来制作循环。当应用开始时,在viewDidAppear中,我会检查NSUserDefaults中是否设置了某个值,如果不是,我会向用户显示UIAlertView UITextView。直到这里一切都好。用户设置用户默认值后,警报视图的alertView:clickedButtonAtIndex:会调用void,使计时器工作:

- (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    [standardUserDefaults setObject:nameField.text forKey:@"host"];
    [standardUserDefaults synchronize];
    [self setUp];
    NSLog(@"called");
}

这是[self setUp];

-(void)setUp {


    timer = [NSTimer timerWithTimeInterval: 1  target: self selector: @selector(reloadData) userInfo: nil repeats: YES];

    [[NSRunLoop mainRunLoop] addTimer: timer forMode: NSDefaultRunLoopMode];
    [self reloadData];
    self.host = [self getHostName:val];
    self.ip = [self getHostIP:val];
    NSLog(@"reached here"); //THIS GETS CALLED SO I THINK IT WORKS


}

这是[self reloadData]

- (void)reloadData {
    NSArray *words = nil;
    words = [[self getUptime] componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
    //int sum = [[words objectAtIndex:0] intValue] / 100.0;
    float sum1 = ([[words objectAtIndex:0] floatValue] / 10.0);
    NSLog(@"%f", sum1);
    [bar1 setProgress:sum1];
    load1.text = [NSString stringWithFormat:@"%f", [bar1 progress]];

    float sum2 = ([[words objectAtIndex:1] floatValue] / 10.0);
    NSLog(@"%f", sum2);
    [bar2 setProgress:sum2];
    load2.text = [NSString stringWithFormat:@"%f", [bar2 progress]];


    float sum3 = ([[words objectAtIndex:2] floatValue] / 10.0);
    NSLog(@"%f", sum3);
    [bar3 setProgress:sum3];
    load3.text = [NSString stringWithFormat:@"%f", [bar3 progress]];

}

问题是tableView单元格没有获取值并保持白色,但是如果你关闭应用程序并再次加载它(当它在用户默认值中有变量时)这个东西很完美,所以我没有知道会发生什么。我也常常在日志中wait_fences: failed to receive reply: 10004003(我知道当你不打电话给superview时会发生这种情况)

2 个答案:

答案 0 :(得分:0)

你打电话给[table reloadData]吗?奇怪的是,您将自己的内部函数命名为与tableview的消息相同。

答案 1 :(得分:0)

呃,我发现了问题。我使用的是在app start上设置的变量val,当用户默认没有那个键时它是空的:/所以我在调用{{1}时只做了NSString *userhost = [standardUserDefaults objectForKey:@"host"];解除警报视图后出现无效