The following code works as expecte开发者_JAVA技巧d on iOS4.3 iPhone and iPad, and iOS5 iPhone, but crashes on iOS5 iPad. This is called for the first view that I call in a Tab based application, when the prior run of the application was cancelled. The user can continue the prior run or reset. I have tried moving this code to both the -viewWillAppear and -viewDidAppear secant, to no avail. Has anyone else experienced this? (Btw, I have confirmed all the connections in my XIBs to make sure it wasn't a problem with iPad parts of this UniversalApp.
- (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;
}
}
Here is the text of the crash -
Current language: auto; currently objective-c
2011-10-12 21:02:55.530 Wasted Time[3884:17603] * Assertion failure in -[UIActionSheet showInView:], /SourceCache/UIKit_Sim/UIKit-1912.3/UIActionSheet.m:4630 2011-10-12 21:02:55.532 APP NAME[3884:17603] Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: view != nil' ** First throw call stack: (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) terminate called throwing an exception(gdb
Blockquote
Here's the Delegate .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
And the .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
Try and call your [super viewDidLoad]; first. Your view probably isn't set up enough to push the actionSheet yet.
Have you turned on ARC (Automatic Reference Counting) for this project? Without ARC, you're leaking objects in the main branch of your if statement.
With ARC enabled, it's going to be releasing those objects for you, which you probably didn't expect, and that's going to cause problems.
Edit: it looks like your tab bar isn't loaded yet (OR: was loaded and now has become unloaded). This would happen if ARC thought it shouldn't stick around any longer. Check to make sure self.tabBarController
points to something real when you call the actionSheet to present itself.
I can tell this because of the exception being thrown, it's saying "you're trying to present it in a nil view", more or less. That's a programmer error. My guess is, you were leaking the tabBarController somewhere else before, and now that you've used ARC, that leak is automatically cleaned up for you, and the tabBarController is getting deallocated.
From the error text: view != nil
from [UIActionSheet showInView:]
, the view is nil. Either the actionSheet
or self.tabBarController.tabBar
is nil. Add some NSLogs to verify neither is nil.
Make things a little esier, replace:
NSString *message_continue = [[NSString alloc] initWithFormat:@"Do you want to Continue the Prior event"];
with
NSString *message_continue = @"Do you want to Continue the Prior event";
How is your delegate setup?
精彩评论