简体   繁体   English

视图在 iOS 4.3 模拟器中显示不正确

[英]Views not displaying correctly in iOS 4.3 simulator

I am working on an app which requires that the user be logged in at all times.我正在开发一个要求用户始终登录的应用程序。 Initially it has a login view, and when the user is logged in this is replaced with a tabbar view.最初它有一个登录视图,当用户登录时,它被替换为一个标签栏视图。 If I build to either my device (iOS 5.0) or to the 5.0 simulator it works fine.如果我构建到我的设备 (iOS 5.0) 或 5.0 模拟器,它工作正常。 However if I build to the 4.3 simulator I get strange problems.但是,如果我构建到 4.3 模拟器,我会遇到奇怪的问题。

For instance: the first tab that it opens onto originally contained the login view - I haven't got round to removing it yet so at the moment as soon as that tab opens it fades from a login view to a menu screen (both are separate views within the first tab).例如:它打开的第一个选项卡最初包含登录视图 - 我还没有开始删除它,所以现在一旦该选项卡打开,它就会从登录视图淡化到菜单屏幕(两者都是分开的第一个选项卡中的视图)。 In iOS4.3 builds this first view does not fade out.在 iOS4.3 中构建此第一个视图不会淡出。

I recoded it to skip past the first screen and have the first tab open directly into the menu screen which has the users Facebook friends list.我将其重新编码为跳过第一个屏幕,将第一个选项卡直接打开到菜单屏幕,其中包含用户 Facebook 好友列表。 I have printed the friends list to the console and it is received correctly - yet the list appears empty in iOS4.3 and works fine in iOS 5.0.我已经将朋友列表打印到控制台并且它被正确接收 - 但该列表在 iOS4.3 中显示为空并且在 iOS 5.0 中工作正常。 These things all worked until I implemented the separate login view (afaik).在我实现单独的登录视图 (afaik) 之前,这些事情都有效。 I'm presuming that I have not implemented the change between views correctly but I'm not sure where it is wrong as I do not get any errors printed to the console, and I can still change between tabs etc.我假设我没有正确实现视图之间的更改,但我不确定哪里错了,因为我没有将任何错误打印到控制台,而且我仍然可以在选项卡等之间进行更改。

This is how I have done it so far (I'll only include relevant parts):到目前为止,这就是我的做法(我只会包括相关部分):

appDelegate.h
@interface AppDelegate : UIResponder <UITabBarControllerDelegate,LoginViewControllerDelegate, otherDelegates>

 FirstViewController *viewController1;
SecondViewController *viewController2;
ThirdViewController *viewController3;
FourthViewController *viewController4;
FifthViewController *viewController5;
loginViewController *lvc;

@property (strong, nonatomic) UITabBarController *tabBarController;

... ...

appDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
lvc = [[loginViewController alloc] initWithNibName:@"loginViewController" bundle:nil];
lvc.delegate = self;
[self.window addSubview:lvc.view];
self.window.rootViewController = lvc;
[self.window makeKeyAndVisible];
}



- (void)loginViewControllerDidFinish:(loginViewController *)loginViewController {

//load windows and tab bar controller
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];

viewController1 = [[[FirstViewController alloc] initWithNibName:@"FirstViewController_iPhone" bundle:nil] autorelease];
viewController2 = [[[SecondViewController alloc] initWithNibName:@"SecondViewController_iPhone" bundle:nil] autorelease];
viewController3 = [[[ThirdViewController alloc] initWithNibName:@"ThirdViewiPhone" bundle:nil] autorelease];
viewController4 = [[[FourthViewController alloc] initWithNibName:@"FourthViewiPhone" bundle:nil] autorelease];
viewController5 = [[[FifthViewController alloc] initWithNibName:@"FifthViewiPhone" bundle:nil] autorelease];
[viewController4 updateTabBar];

self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, viewController3, viewController4, viewController5, nil];
self.window.rootViewController = self.tabBarController;
[self.window addSubview:self.tabBarController.view];
[self.window makeKeyAndVisible];
}


//called when logout button is pressed
- (void)removeTabBarView
{
//[self.tabBarController.view removeFromSuperview];
[self.window addSubview:lvc.view];
self.window.rootViewController = lvc;
 [self.window makeKeyAndVisible];
}

Edit: this is called in the appDelegate once all of the login data has been received.编辑:一旦收到所有登录数据,就会在 appDelegate 中调用它。

[self loginViewControllerDidFinish:lvc];

The fact it works fine in iOS 5.0 is what's really throwing me, I'm pretty new to app development so I have no idea how this could be done differently.它在 iOS 5.0 中运行良好的事实真正让我感到震惊,我是应用程序开发的新手,所以我不知道如何以不同的方式完成这件事。 If anyone has any ideas I would be very appreciative.如果有人有任何想法,我将不胜感激。 Thanks谢谢

As usual I spent ages looking at it, gave up and decided to ask for help, and then realised a way to do it about half an hour later.像往常一样,我花了很长时间看着它,放弃并决定寻求帮助,然后在大约半小时后想到了一种方法。

I just put this after I setup the tabbar and set it as the view controller (ie put the login view on top):我只是在设置选项卡栏并将其设置为视图 controller 之后放置它(即将登录视图放在顶部):

lvc = [[loginViewController alloc] initWithNibName:@"loginViewController" bundle:nil];
lvc.delegate = self;
[self.window addSubview:lvc.view];

Then I just use:然后我只使用:

[lvc.view removeFromSuperview];

to remove it once I'm logged in. Still don't know why the other way didn't work in iOS 4.3 though, so if anyone can provide an answer to that I'll still mark a correct answer - in case anyone else has the same problem in future.登录后删除它。仍然不知道为什么其他方法在 iOS 4.3 中不起作用,所以如果有人可以提供答案,我仍然会标记正确答案 - 以防其他人将来有同样的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM