2014-10-29 31 views
0

我正在嘗試更新標籤。當我點擊標籤時,文本將移至textview,然後每次使用更新的文本創建新標籤時,我點擊Done。我應該如何更新相同的標籤?我正在使用`singleton'來做這件事。用ios中的新文本更新相同的標籤

+0

你應該張貼你的代碼,這樣的人可以幫你。 – rdelmar 2014-10-29 06:23:19

+0

我正試圖解決這個問題。 http://stackoverflow.com/questions/26601832/removing-label-if-exist-in-ios?noredirect=1#comment41819148_26601832 – user3763512 2014-10-29 07:05:32

回答

0

嘗試搜索有關特定UI元素的IBOutlets和屬性。比如,你想在這種情況下更改你的UILabel的.text屬性。這裏絕對沒有使用單身。

+0

我使用的是單身人士,因爲我從一個視圖控制器傳遞數據到另一個..我發現單身人士有用+容易這樣做。 – user3763512 2014-10-29 07:21:17

+0

但不是最好的方法。使用導航控制器,push-pop和創建對象。它應該有所幫助。我其實不瞭解你想要達到的目標。只有當你可以更具體。 – 2014-10-29 09:37:25

+0

我用它做了單身:)我在singleton類中聲明瞭bool變量,並在整個過程中使用它。 – user3763512 2014-10-31 07:12:17

0

如果您沒有標籤實例,請嘗試使用viewWithTag獲取現有標籤。

例如:

UIView *myView = [[UIView alloc] initWithFrame:CGRectMake(10, 60, 200, 100)]; 
[self.view addSubview:myView]; 

UILabel *myLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 10, CGRectGetWidth(myView.frame), 50)]; 
[myLabel setTag:1001]; // We can use this tag to find the label from different place. 
[myView addSubview:myLabel]; 

要找到標籤

UILabel *mLabel = (UILabel *) [myView viewWithTag:1001]; 
if (mLabel) { 
    [mLabel setText:@"Hello"]; 
}