0

我将 InfoViewController 的视图加载为MainViewController像这样的子视图(在 .h 中声明):

- (void)viewDidLoad
{
[super viewDidLoad];
infoViewController = [[InfoViewController alloc] initWithNibName:@"InfoViewController" bundle:nil];
mainInfoView = (MainInfoView *)[mainInfoViewController view];
 }

(MainViewController 是从 tableviewcontroller 单元的 segue 推送呈现的,并且有一个导航栏。)

这是在InfoViewControllerviewDidLoad 中设置视图的大小:

- (void)viewDidLoad
{
[super viewDidLoad];
self.view.frame = CGRectMake(130, 0, 178, 299);
}

在 InfoViewController 的尺寸检查器中,我设置了相同的尺寸(178,高度:299)。我为 XIB 中的 InfoViewController 和 Storyboard 中的 MainViewController 禁用了“使用自动布局”。

我在InfoViewController. 它们在 .h 中用属性声明并在 .m 中合成。并连接到 XIB 中的元素。它们的内容在 viewWillAppear 中定义MainViewController如下:

- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
 infoViewController.kategoriLabel.text = [[objArr objectAtIndex:detailIndex] objectForKey:@"Type"];
 }

当我运行应用程序并输入此视图时,一些标签、图像和文本视图突然被放置在看似随机的位置。这只发生在某些元素上。

我在另一个应用程序中做了同样的事情,它在模拟器(iPhone 4 版本 6,0)和 iPhone 5 设备上都可以正常工作,但在这个应用程序中它只是在两者上都变得混乱。当我比较应用程序时,我似乎在实用程序的任何地方或其他任何地方都找不到任何不同的地方。

如果您遇到过类似的事情并解决了它,或者您可能知道是什么原因造成的,我将不胜感激您的回答。谢谢。

PS。我正在使用 Xcode 4.5.1

4

1 回答 1

2

我有一个不同的问题,但我的蛮力解决方案也可能对你有用。就我而言,我想禁用一系列视图控制器中最后一项的导航栏。但是,IB 不会让您删除导航栏,所以我必须在 viewWillAppear 中手动完成。然而,一旦栏被隐藏,IOS 将我在 IB 中定义的所有按钮和对象上移(现在隐藏)导航栏的高度。

我在 Controller 的 viewWillAppear 中使用了以下内容。(当我在 viewWillAppear 中尝试此操作时,对象往往会明显移动)

-(void) viewWillAppear:(BOOL)animated
{
    //turn off nav bar
    [[self navigationController]setNavigationBarHidden:YES animated:NO];

    //correct positions of items that shift when the bar disappears
    myThing.center = CGPointMake(desired_x_coord, desired_y_coord);
    myOtherThing.center = CGPointMake(desired_x_coord2, desired_y_coord2);
    ...etc...

    //don't forget to call the base class
    [super viewWillAppear:animated];
}

烦人,但工作。如果找不到对象移动的来源,可以尝试使用 viewWillAppear 强制它们的位置。

于 2012-11-27T02:46:10.257 回答