iphone to ipad, iphone 4 uialertview problems
So I've upgraded the code to the ipad (i.e. converted to a universal app). However, the UIAlertview rendering seems to be off for IOS4. Instead of being positioned in the middle, it jumps up and is displayed on top, with half the box cut off. Same goes for landscape orientation.
It is my u开发者_C百科nderstanding that the UIalertview is always set in the middle? I looked through the code and I did not set up the frame/position anywhere in the code. This only happens for 4.0, on both the iphone 4 and the itouch running 4.0. Every other version is fine, including the ipad. Any thoughts?
Thanks.
Seems to be a bug. I also had the Problem on iPad with iOS 3.2.
Solution:
a) Check your app state: In iOS 4 just use
[UIApplication sharedApplication].applicationState
Older iOS: Store your app state manually:
-(void)applicationWillResignActive:(UIApplication *)application
{
self.appIsInBackground = YES;
}
-(void)applicationWillTerminate:(UIApplication *)application
{
self.appIsInBackground = YES;
}
-(void)applicationDidBecomeActive:(UIApplication *)application
{
// Open your UIAlert here if self.appIsInBackground == YES;
self.appIsInBackground = NO;
}
b) open the UIAlert after the app did become active, as shown above in the comments.
Does your alert have any Textfields added ?
Because in 4.0+ iOS scrolls the alertview to visible part if you have a textfield in the alertview.
I have the same problem for iPad 3.2 when application resign active and in that time alert is shown that alert will be shown on top left corner. So i fixed using following code in the method -(void)applicationDidBecomeActive:(UIApplication *)application
//Check that key window is alert view
if ([[[UIApplication sharedApplication].keyWindow description] hasPrefix:@"<_UIAlertOverlayWindow"]) {
//Yes then check for subviews tht are alertViews
UIWindow *alertViewWindow = [UIApplication sharedApplication].keyWindow;
NSArray *subViews = [alertViewWindow subviews];
for (UIView *subview in subViews)
{
if ([subview isKindOfClass:[UIAlertView class]])
{
//Retain it
UIAlertView *alertView = (UIAlertView *)[subview retain];
//Now dismiss it and then show it again
[alertView dismissWithClickedButtonIndex:0 animated:NO];//Here ClickedButtonIndex must be according to cancel button
//Show the alert view again
[alertView show];
//Release previsous retained object
[alertView release];
}
}
}
精彩评论