如何获取UIView组件的名称或标识符

问题描述 投票:0回答:1

在下面的代码中,我想要-firstView-的任何标识符,如下面的代码所示。我尝试了以下操作:

//NSLog(@"_[uiviews[0] _description] = %@" , [uiviews[0] _description]);
  //NSLog(@"[uiviews[0] nameLabel] = %@" , [uiviews[0] nameLabel]);
    //NSLog(@"[uiviews[0] textLabel]= %@" , [[uiviews[0] textLabel].text);
 NSString *r = [uiviews[0] textLabel].text;
    NSLog(@"[uiviews[0] textLabel]= %@", r);a

但是,一旦激活其中任何一个,应用程序就会崩溃。您能否让我知道如何访问名称或标识该UIView的任何字符串。

code

        UIView *firstView = uiviews[0];
objective-c uiview appdelegate
1个回答
0
投票

使用UIView.tag识别您的应用中的视图:

UIView* anotherView = [UIView new];
anotherView.tag = 100;
[view addSubview:anotherView];
UIView* anotherViewAgain = [view viewWithTag:100];
© www.soinside.com 2019 - 2024. All rights reserved.