iphone - 如何从 View 中了解标签值

标签 iphone uiview tags

我正在制作一个应用程序,在该应用程序中我有一个 View ,可以在其中显示 friend 的详细信息。 所以,如果我需要更改细节。我必须检查标签才能更改它。 在这里,我为每个标签设置了标签值。

如果用户按下标签,新的文本字段将出现在 View 上,用户可以更改详细信息。

为此,我编写了触摸开始方法,其中我正在检查触摸值... 但是每当我触摸任何标签时,我都会将 View 的标签值设置为零,因为我应该获取我单击的标签的标签值。

我的代码如下所示...

txtTmp = [[UITextField alloc] init];    

//txtTmp is the textfield which should appear as super view of the label where i have clicked

    txtTmp.delegate=self;

self.lblName.tag=11;

UITouch *touch = [touches anyObject]; 

//这里即使我启用了用户交互,我得到的标签值为 0...

NSLog(@"view.tag = %d",touch.view.tag);

if(touch.view.tag==11) {



    [txtTmp setFrame:CGRectMake(162, 43, 138, 50)];
    txtTmp.text=lblName.text;
    [self.view addSubview:txtTmp];
    [txtTmp becomeFirstResponder];
    temp=1;



}

如果您对我的问题有任何疑问..请回复我....

谢谢

最佳答案

您应该启用 self.lblName 的用户交互。

   [self.lblName setUserInteractionEnabled:YES];

您还可以使用viewWithTag消息在touchesbegan方法中检查触摸标签:

UITouch *touch = [touches anyObject];

if(touch.view == [self.view viewWithTag:11]) 
{
    [txtTmp setFrame:CGRectMake(162, 43, 138, 50)];
    txtTmp.text=lblName.text;
    [self.view addSubview:txtTmp];
    [txtTmp becomeFirstResponder];
    temp=1;
}

关于iphone - 如何从 View 中了解标签值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10477190/

相关文章:

iphone - 一个应用程序中的多个 plist 文件

ios - 在 iOS 上,CALayer 位图(CGImage 对象)如何显示到显卡上?

swift - UIImageView.Image 集重新定位父 View

html - 在样式标签中编辑滚动条

mysql GROUP_CONCAT DISTINCT 多列

iphone - 针对不同国家/地区的游戏本地化

ios - 试图理解类型属性,例如 static 和 swift 的 class 关键字

regex - Sed 正则表达式多行 - 替换 HTML

iphone - Sprite Atlas 和 @2x 图像

ios - 将 UILabel 的基类 UIView 更改为自定义 UIView?