2012-07-12 77 views
0

我有一个UIViewController带有从外部服务器获取其文本集的标签。在viewDidLoad我补充一下:如何让UIViewController正确刷新/更新其视图?

[self.view addSubview:label]; 

几分钟后,服务器将更新后的文本,并在应用程序,我按下一个按钮激活此:

[self.view setNeedsDisplay]; 

但标签的文本不得到更新,直到我重新编译应用程序。我如何获得子视图标签刷新/从服务器获取新文本?

+0

当光洁度API调用服务器(实际上当你从API调用中获得文本时)。那么你的文字与你对吗?所以PLZ使用'UILabel'的'setText:'方法在标签上设置文本。 – 2012-07-12 04:24:05

+0

我需要每次按下按钮时更新文本,我在哪里添加setText? – sebi 2012-07-12 04:43:07

+0

如果您正在设置API响应中的文本,那么您每次按下按钮时都必须调用api? – 2012-07-12 05:21:17

回答

0

label.text = @"new title";怎么样?

0

您需要在Buttons事件中添加setText。

-(void) viewDidLoad{ 
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
[button addTarget:self action:@selector(buttonPressMethod:) forControlEvents:UIControlEventTouchDown]; 
button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0); 
[self.view addSubview:button]; 

    [super viewDidLoad]; 
} 

-(void) buttonPressMethod:(id) sender 
{ 
    label.text = @"The updated text from the server"; 
} 
0

- (无效)viewWillAppear中
{
的NSTimer *聊天= [的NSTimer scheduledTimerWithTimeInterval:40目标:自选择器:@selector(的GetData)USERINFO:无重复:YES]; //方法将要求每40秒

}

- (无效)的GetData
{
呼叫从服务器中的数据和标签数据替换
}