ios - 查看标签返回 0 值
<p><p>我在 iPad 的 iOS 项目中遇到标签值的奇怪问题</p>
<p><strong>我在界面生成器中给出了我 View 的不同 subview 一些标签 1,2,3,4,5....</strong></p>
<p>但是当我尝试动态获取标签值时,它给了我 0 值。</p>
<pre><code>NSArray *pSubviews = ;
// Enumerate the portrait view
for (int sv = 0; sv < ; sv++)
{
UIView *pObject = (id);
NSLog(@"tag %d",pObject.tag);
}
</code></pre>
<p><strong>结果</strong></p>
<pre><code>2016-05-07 22:12:58.832 tag 0
2016-05-07 22:12:58.832 tag 0
2016-05-07 22:12:58.832 tag 0
2016-05-07 22:12:58.832 tag 0
2016-05-07 22:12:58.832 tag 0
2016-05-07 22:12:58.832 tag 0
</code></pre>
<p>我在应用委托(delegate)启动方法中为 iPadView 动态设置 View 。</p>
<pre><code> myViewController *ldVC;
if (IS_IPAD)
{
ldVC = [initWithNibName:@"myViewController_iPad" bundle:];
}
else
{
ldVC = [initWithNibName:@"myViewController" bundle:nil];
}
UINavigationController *navVC = [initWithRootViewController:ldVC];
self.window.rootViewController=navVC;
</code></pre>
<p>查看层次结构::</p>
<p> <a href="/image/NhbK8.png" rel="noreferrer noopener nofollow"><img src="/image/NhbK8.png" alt="enter image description here"/></a> </p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>如果您在 viewDidLoad 方法中运行此 View ,则可能尚未设置 View 。尝试在 viewDidLayoutSubviews 中运行它</p></p>
<p style="font-size: 20px;">关于ios - 查看标签返回 0 值,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/37091193/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/37091193/
</a>
</p>
页:
[1]