how to know about the tag value from the view

Refresh

December 2018

Views

89 time

2

I am making an App in which i have a view where i am showing friends details. So, If i need to change the details. I will have to check on the label to change it. Here,I have set tag value for each label.

If the user presses a label the new text field will appear on the view and the user can change the Details.

So for this i have written touch began method in which i am checking the touch value... But whenever i am touching any label i am getting the tag value of view as zero where as i should get the tag value of the label on wich i have clicked .

My code is shown below...

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]; 

//here i am getting the tag value as 0 even if i have enabled the user interaction...

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;



}

If u have any problem regarding my question..Please get back to me....

Thanks,

1 answers

5

Вы должны включить взаимодействие с пользователем в self.lblName.

   [self.lblName setUserInteractionEnabled:YES];

Также вы можете проверить на прикоснулся метки в методе touchesbegan используя viewWithTag сообщение:

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;
}