我在 iPad 的 iOS 项目中遇到标签值的奇怪问题
我在界面生成器中给出了我 View 的不同 subview 一些标签 1,2,3,4,5....
但是当我尝试动态获取标签值时,它给了我 0 值。
NSArray *pSubviews = [self.view subviews];
// Enumerate the portrait view
for (int sv = 0; sv < [pSubviews count]; sv++)
{
UIView *pObject = (id)[pSubviews objectAtIndex : sv];
NSLog(@"tag %d",pObject.tag);
}
结果
2016-05-07 22:12:58.832[1562:47169] tag 0
2016-05-07 22:12:58.832[1562:47169] tag 0
2016-05-07 22:12:58.832[1562:47169] tag 0
2016-05-07 22:12:58.832[1562:47169] tag 0
2016-05-07 22:12:58.832[1562:47169] tag 0
2016-05-07 22:12:58.832[1562:47169] tag 0
我在应用委托(delegate)启动方法中为 iPad View 动态设置 View 。
myViewController *ldVC;
if (IS_IPAD)
{
ldVC = [[myViewController alloc]initWithNibName"myViewController_iPad" bundle:[NSBundle mainBundle]];
}
else
{
ldVC = [[myViewController alloc]initWithNibName"myViewController" bundle:nil];
}
UINavigationController *navVC = [[UINavigationController alloc]initWithRootViewController:ldVC];
self.window.rootViewController=navVC;
查看层次结构::
如果您在 viewDidLoad 方法中运行此 View ,则可能尚未设置 View 。尝试在 viewDidLayoutSubviews 中运行它
关于ios - 查看标签返回 0 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37091193/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |