以下代码在iOS4.3 iPhone和iPad以及iOS5 iPhone上按预期工作,但在iOS5 iPad上崩溃。当前一次运行应用程序被取消时,我会调用基于选项卡的应用程序中调用的第一个视图。用户可以继续之前的运行或重置。我已经尝试将此代码移动到-viewWillAppear和-viewDidAppear割线,但无济于事。还有其他人经历过这个吗? (顺便说一下,我已经确认了我的XIB中的所有连接,以确保这个UniversalApp的iPad部分没有问题。
- (void)viewDidLoad {
BOOL continueYesNo;
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
continueYesNo = [prefs boolForKey:@"keyContinueMeeting"];
if (continueYesNo) {
NSString *message_continue = [[NSString alloc] initWithFormat:@"Do you want to Continue the Prior event"];
UIActionSheet *actionSheet = [[UIActionSheet alloc]
initWithTitle:message_continue
delegate:self
cancelButtonTitle:@"Reset"
destructiveButtonTitle:@"Continue Meeting"
otherButtonTitles:nil];
[actionSheet showFromTabBar:self.tabBarController.tabBar]; // This is the line that crashes. The program checks for a terminated APP and status in preferences
}
else {
resetStuff.hidden = YES;
}
}
这是崩溃的文本 -
Current language: auto; currently objective-c
2011-10-12 21:02:55.530浪费时间[3884:17603] *断言失败 - [UIActionSheet showInView:],/ SourceCache / UIKit_Sim / UIKit-1912.3 / UIActionSheet.m:4630 2011-10-12 21:02:55.532 APP NAME [3884:17603] 由于未捕获异常'NSInternalInconsistencyException'而终止应用程序,原因:'无效参数不满意:view != nil' * *第一次抛出调用堆栈: (0x1d87052 0x1f18d0a 0x1d2fa78 0x2742db 0x90b47e 0x90b122 0x90b356 0x90b653 0x6fe1 0x60064e 0x61bb89 0x61b9bd 0x619f8a 0x619e2f 0x617ffb 0x61885a 0x601fbf 0x60221b 0x6030f1 0x571fec 0x577572 0x57172b 0x2b86 0x5389d6 0x5398a6 0x548743 0x5491f8 0x53caa9 0x2315fa9 0x1d5b1c5 0x1cc0022 0x1cbe90a 0x1cbddb4 0x1cbdccb 0x5392a7 0x53aa9b 0x2abd 0x2325) 终止调用抛出异常(gdb
块引用
这是代表.h
#import <UIKit/UIKit.h>
@interface W_AppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
UITabBarController *rootController;
float floatVal;
NSDate *currentTime;
NSDate *previousTime;
NSDate *currentQTime;
NSDate *previousQTime;
BOOL continueMeeting;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UITabBarController *rootController;
@property (nonatomic, readwrite) float floatVal;
@property (nonatomic, readwrite) BOOL continueMeeting;
@property (nonatomic, retain) NSDate *currentTime;
@property (nonatomic, retain) NSDate *previousTime;
@property (nonatomic, retain) NSDate *currentQTime;
@property (nonatomic, retain) NSDate *previousQTime;
@end
而.m
#import "W.h"
@implementation W_AppDelegate
@synthesize window;
@synthesize rootController;
@synthesize floatVal;
@synthesize currentTime;
@synthesize previousTime;
@synthesize currentQTime;
@synthesize previousQTime;
@synthesize continueMeeting;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[window addSubview:rootController.view];
[window makeKeyAndVisible];
return YES;
}
@end
答案 0 :(得分:1)
您是否为此项目启用了ARC(自动引用计数)?如果没有ARC,则会在if语句的主分支中泄漏对象。
启用ARC后,它会为你释放那些你可能没想到的对象,这会引起问题。
编辑:看起来您的标签栏尚未加载(或者:已加载,现在已卸载)。如果ARC认为它不应该再坚持下去,就会发生这种情况。当您调用actionSheet呈现自己时,请检查以确保self.tabBarController
指向真实的东西。
我可以告诉这个,因为被抛出的异常,它或多或少地说“你试图以零视图呈现它”。这是一个程序员错误。我的猜测是,你之前在其他地方泄漏了tabBarController,现在你已经使用过ARC,这个泄漏会自动清理掉,并且tabBarController正在被释放。
答案 1 :(得分:1)
来自view != nil
的错误文字[UIActionSheet showInView:]
,视图为零。 actionSheet
或self.tabBarController.tabBar
为零。添加一些NSLog以验证两者都不是。
让事情变得更有点,替换:
NSString *message_continue = [[NSString alloc] initWithFormat:@"Do you want to Continue the Prior event"];
与
NSString *message_continue = @"Do you want to Continue the Prior event";
您的代表是如何设置的?
答案 2 :(得分:1)
尝试并调用[super viewDidLoad];第一。您的视图可能设置不足以推送actionSheet。