Hi in my project i need to update a label according to the events performed.
Suppose I'm interacting with the server then the label should display following text 1.Connecting to t开发者_如何学运维he server 2.Received response from the server etcCan you help me?
Your question could be more complete.
If you're doing things programmatically you need to call the setText:
method on your instance of UILabel with the new message each time. Something like:
//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?"];
Update the label text whenever you want, and then call the setNeedsDisplay function on it:
myLabel.text=@"Initial Text";
[myLabel setNeedsDisplay];
You have to create the outlet of UILabel. and then set the "labelname.text" to what u want according to the event.
you can set the text property of the label for setting text.
For example: In While connecting to the server event:
myLabel.text=@"Connecting to the server";
In the event When you recieve response
myLabel.text=@"Received response from the server";
and so on....
ADD LABEL THROUGH CODE This is how to add the label through code because i cant show the binding here in .h file
UILabel* myLabel;
in .m file viewDidLoad (Note: Dont alloc the label again in code except here)
myLabel=[[UILabel alloc]initWithFrame:CGRectMake(10,10,200,40)];//SET THE FRAME ACCORDING TO YOUR USE
[self.view addSubview:myLabel];
myLabel.text=@"Initial Text";
Release the label
- (void)dealloc {
[myLabel Release];
}
精彩评论