重新加载数组并再次添加随机值到视图

时间:2011-10-28 07:49:18

标签: objective-c xcode view

我创建一个创建随机值的数组和数组。并写入标签。我添加了NSTimer,但无法重新加载值。我想用计时器重新加载数据。我怎么能这样做; 我的代码在下面

 NSArray *array = [NSArray arrayWithObjects:

                      [NSNumber numberWithInt:arc4random() % 100 * -1],
                      [NSNumber numberWithInt:arc4random() %(100) * -1],
                      [NSNumber numberWithInt:arc4random() %(100) * -1],
                      [NSNumber numberWithInt:arc4random() %(100)],
                      [NSNumber numberWithInt:arc4random() %(100)],
                      [NSNumber numberWithInt:arc4random() %(100)],
                      [NSNumber numberWithInt:arc4random() %(100)],
                      [NSNumber numberWithInt:arc4random() %(100)],
                      [NSNumber numberWithInt:arc4random() %(100)],
                      [NSNumber numberWithInt:arc4random() %(100)],nil];


NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval: 5.0
                                                      target: self
                                                    selector:@selector(selectorSwitcher:)
                                                    userInfo: nil repeats:YES];



-(void)selectorSwitcher:(NSTimer *)timer {

    [array removeAllObjects];

    //Label
    lblNumber.text= nil;


    [createview setNeedsDisplay];
    [myView setNeedsDisplay];

}

1 个答案:

答案 0 :(得分:2)

如果您在UITableView的数据源或UITableViewController中执行此操作,您需要的是:

[self.tableView reloadData];