如何更新uilabel文本

时间:2010-09-27 08:12:06

标签: iphone xcode

您好,在我的项目中,我需要根据所执行的事件更新标签 假设我正在与服务器交互,那么标签应显示在文本之后 1.连接到服务器
2.从服务器等接收响应

你能帮助我吗?

4 个答案:

答案 0 :(得分:6)

您的问题可能更完整。

如果您以编程方式执行操作,则需要每次使用新消息在您的UILabel实例上调用setText:方法。类似的东西:

//In practice use a smaller frame.

UILabel *label = [[UILabel alloc] initWithFrame:[window bounds]];

[label setText:@"Waiting for the server to do something interesting..."];

[window addSubview: label];

//later on....

[label setText:@"The server just sneezed! What shall I do?"];

答案 1 :(得分:4)

随时更新标签文本,然后在其上调用setNeedsDisplay函数:

myLabel.text=@"Initial Text";
[myLabel setNeedsDisplay];

答案 2 :(得分:0)

你必须创建UILabel的出口。然后根据事件将“labelname.text”设置为您想要的内容。

答案 3 :(得分:0)

您可以设置标签的文本属性以设置文本。

例如: 在连接到服务器事件时:

myLabel.text=@"Connecting to the server";

如果您收到回复

myLabel.text=@"Received response from the server";

依旧......

通过代码添加标签 这是如何通过代码添加标签,因为我不能在这里显示绑定 在.h文件中

UILabel* myLabel;
.m文件中的

viewDidLoad(注意:除了这里,不要再在代码中再分配标签)

myLabel=[[UILabel alloc]initWithFrame:CGRectMake(10,10,200,40)];//SET THE FRAME ACCORDING TO YOUR USE
[self.view addSubview:myLabel];
myLabel.text=@"Initial Text";

发布标签

- (void)dealloc {
    [myLabel Release];
}
相关问题