2014-10-29 50 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"]; 
}