2010-09-27 91 views
-2

嗨,在我的項目中,我需要根據執行的事件更新標籤。
想我與服務器交互則標籤應顯示以下文字
1.連接到服務器,從服務器等如何更新uilabel文字

你能幫我
2.Received迴應?

回答

0

您必須創建UILabel的出口。然後根據事件將「labelname.text」設置爲你想要的。

+0

亞我嘗試過,但第二個事件沒有更新的文字。 – iphoneStruggler 2010-09-27 08:47:02

+0

你應該發佈你的部分代碼來完成你的問題。張貼你有問題的地方。 – Jack 2010-09-27 09:12:44

+0

我已經通過接口生成器在視圖上放置了一個標籤。在.h文件中,我聲明瞭IBOutlet UILabel * lblmsg;在.m - (void)connectionDidFinishLoading:(NSURLConnection *)連接 {self_ CompleteWebRequest]; NSLog(@「請求已成功加載」); lblmsg.text = @「請求已成功加載」; }並在另一個事件中將其更新爲lblmsg.text = @「顯示圖像」;而在調試器中,標籤正在更新,但在視圖中顯示的是先前的文本 – iphoneStruggler 2010-09-27 09:27:01

0

您可以設置用於設置文本的標籤的文本屬性。

例如: 在同時連接到服務器的事件:

[email protected]"Connecting to the server"; 

在活動當您收到響應

[email protected]"Received response from the server"; 

等等....

ADD標籤通過代碼 這是如何通過代碼添加標籤,因爲我不能顯示雙(:不要再ALLOC標籤代碼,除了這裏注)

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

發佈標籤

這裏nding 在.h文件中

UILabel* myLabel; 

在.m文件viewDidLoad中

- (void)dealloc { [myLabel Release]; } 
+0

我試過這個東西,但標籤不是更新到第二個消息。 – iphoneStruggler 2010-09-27 08:46:18

+0

原因可能是您再次分配了標籤或您的標籤未正確綁定。檢查它是否在xib中正確綁定。 – 2010-09-27 09:06:31

+0

我已經添加了更好的理解代碼...希望幫助 – 2010-09-27 09:12:56

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個空格。使用工具欄上的101010按鈕將其快速轉換爲代碼塊。 – kennytm 2010-09-27 09:14:40

+0

好點,謝謝。 – SK9 2010-09-28 01:03:15

+0

'[label setText:@「myString」]'和'label.text = @「myString」'有區別嗎? – physicalattraction 2015-06-18 12:00:43

4

更新,只要你想要的標籤文本,然後調用其setNeedsDisplay功能:

[email protected]"Initial Text"; 
[myLabel setNeedsDisplay];