Objective c iOS7中的UIAlertView崩溃

Objective c iOS7中的UIAlertView崩溃,objective-c,uialertview,ios7,Objective C,Uialertview,Ios7,我们在iOS 6环境中编译并部署了一个应用程序。但是,现在每当显示警报时,该应用程序都会在iOS 7中崩溃。 应用程序只是在[alertView show]中崩溃 但是,同样的应用程序在iOS 6中运行得非常完美 显示警报的代码 -(void)displayAlertWithMessage:(NSString *)message withTitle:(NSString *)title andTag:(int)tag { UIAlertView *alertView = [[UIAlert

我们在iOS 6环境中编译并部署了一个应用程序。但是,现在每当显示警报时,该应用程序都会在iOS 7中崩溃。 应用程序只是在[alertView show]中崩溃

但是,同样的应用程序在iOS 6中运行得非常完美

显示警报的代码

-(void)displayAlertWithMessage:(NSString *)message withTitle:(NSString *)title andTag:(int)tag
{
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:title message:message delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alertView show];
}
像这样打电话

[self displayAlertWithMessage:@"Please enter valid username!" withTitle:nil andTag:1];
这是坠机日志

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </Users/developer/Library/Application Support/iPhone Simulator/7.0/Applications/A0BCB945-8E4A-4D06-BEE8-240FF45ECF78/MyProject.app> (loaded)' with name '_UIModalItemAppViewController''
*** First throw call stack:
(
    0   CoreFoundation                      0x003176f4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x027c88b6 objc_exception_throw + 44
    2   CoreFoundation                      0x003174cb +[NSException raise:format:] + 139
    3   UIKit                               0x015d1bec -[UINib instantiateWithOwner:options:] + 951
    4   UIKit                               0x01444f05 -[UIViewController _loadViewFromNibNamed:bundle:] + 280
    5   UIKit                               0x014456ad -[UIViewController loadView] + 302
    6   UIKit                               0x014459ae -[UIViewController loadViewIfRequired] + 78
    7   UIKit                               0x01445eb4 -[UIViewController view] + 35
    8   UIKit                               0x018dc9da -[_UIModalItemsCoordinator _presentingViewControllerForAlertCompatibilityCreateIfNeeded:] + 248
    9   UIKit                               0x018dc8dd -[_UIModalItemsCoordinator _presentingViewControllerForAlertCompatibility] + 41
    10  UIKit                               0x01812801 -[UIAlertView(Private) popupAlertAnimated:animationType:atOffset:] + 382
    11  UIKit                               0x01812c1d -[UIAlertView(Private) popupAlertAnimated:animationType:] + 56
    12  UIKit                               0x01817c17 -[UIAlertView showWithAnimationType:] + 48
    13  UIKit                               0x01817c45 -[UIAlertView show] + 41
    14  MyProject                        0x000330a8 -[LoginViewController displayAlertWithMessage:withTitle:andTag:] + 232
    15  MyProject                        0x00032e8b -[LoginViewController isValidContent] + 299
    16  MyProject                        0x00033136 -[LoginViewController showSetPinView] + 54
    17  libobjc.A.dylib                     0x027da874 -[NSObject performSelector:withObject:withObject:] + 77
    18  UIKit                               0x0133524c -[UIApplication sendAction:to:from:forEvent:] + 108
    19  UIKit                               0x013351d8 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
    20  UIKit                               0x0142ba5d -[UIControl sendAction:to:forEvent:] + 66
    21  UIKit                               0x0142be20 -[UIControl _sendActionsForEvents:withEvent:] + 577
    22  UIKit                               0x0142b0cf -[UIControl touchesEnded:withEvent:] + 641
    23  UIKit                               0x0137221d -[UIWindow _sendTouchesForEvent:] + 852
    24  UIKit                               0x01372e84 -[UIWindow sendEvent:] + 1232
    25  UIKit                               0x01346b86 -[UIApplication sendEvent:] + 242
    26  MyProject                        0x000c2c75 -[Application sendEvent:] + 101
    27  UIKit                               0x0133135f _UIApplicationHandleEventQueue + 11421
    28  CoreFoundation                      0x002a096f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
    29  CoreFoundation                      0x002a02fb __CFRunLoopDoSources0 + 235
    30  CoreFoundation                      0x002bd3ce __CFRunLoopRun + 910
    31  CoreFoundation                      0x002bcbf3 CFRunLoopRunSpecific + 467
    32  CoreFoundation                      0x002bca0b CFRunLoopRunInMode + 123
    33  GraphicsServices                    0x036f0a27 GSEventRunModal + 192
    34  GraphicsServices                    0x036f084e GSEventRun + 104
    35  UIKit                               0x01333f0b UIApplicationMain + 1225
    36  MyProject                        0x00006612 main + 178
    37  MyProject                        0x00006555 start + 53
)
libc++abi.dylib: terminating with uncaught exception of type NSException
***由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“无法在捆绑包中加载NIB:“NSBundle(loaded)”,名称为“\u UIModaliteMapViewController”
***第一次抛出调用堆栈:
(
0 CoreFoundation 0x003176f4例外预处理+180
1 libobjc.A.dylib 0x027c88b6 objc_异常_抛出+44
2 CoreFoundation 0x003174cb+[N异常提升:格式:][139
3 UIKit 0x015 D1BEC-[UINib实例化所有者:选项:][951
4 UIKit 0x0144F05-[UIViewController\u loadViewFromNibNamed:bundle:][280
5 UIKit 0x014456ad-[UIViewController loadView]+302
6 UIKit 0x014459ae-[UIViewController loadViewIfRequired]+78
7 UIKit 0x01445eb4-[UIViewController视图]+35
8 UIKit 0x018dc9da-[\u UIModalItemsCoordinator\u PresentingViewController for AlertCompatibility CreateIf Needed:+248
9 UIKit 0x018dc8dd-[\u UIModalItemsCoordinator\u presentingViewControllerForAlertCompatibility]+41
10 UIKit 0x01812801-[UIAlertView(专用)popupAlertAnimated:animationType:atOffset:+382
11 UIKit 0x01812c1d-[UIAlertView(专用)popupAlertAnimated:animationType:][56
12 UIKit 0x01817c17-[UIAlertView showWithAnimationType:][48
13 UIKit 0x01817c45-[UIAlertView显示]+41
14 MyProject 0x000330a8-[LoginViewController显示警报,带消息:带标题:和标签:][232
15 MyProject 0x00032e8b-[LoginView控制器有效内容]+299
16 MyProject 0x00033136-[LoginViewController showSetPinView]+54
17 libobjc.A.dylib 0x027da874-[NSObject性能选择器:withObject:withObject:+77
18 UIKit 0x0133524c-[UIApplication sendAction:to:from:forEvent:][108
19 UIKit 0x013351d8-[UIApplication sendAction:toTarget:fromSender:forEvent:+61
20 UIKit 0x0142ba5d-[UIControl发送操作:发送到:forEvent:+66
21 UIKit 0x0142be20-[UIControl\u发送操作预防:带事件:][577
22 UIKit 0x0142b0cf-[UIControl触摸已设定:带事件:][641
23 UIKit 0x0137221d-[UIWindow\u sendTouchesForEvent:+852
24 UIKit 0x01372e84-[UIWindow sendEvent:+1232
25 UIKit 0x01346b86-[UIApplication sendEvent:+242
26 MyProject 0x000c2c75-[应用程序发送事件:][101
27 UIKit 0x0133135f _UIApplicationHandleEventQueue+11421
28 CoreFoundation 0x002a096f运行循环正在调用源0执行功能15
29 CoreFoundation 0x002a02fb__CFRunLoopDoSources0+235
30 CoreFoundation 0x002bd3ce u CFRunLoopRun+910
31 CoreFoundation 0x002bcbf3 CFRunLoopRunSpecific+467
32 CoreFoundation 0x002bca0b CFRunLoopRunInMode+123
33图形服务0x036f0a27 GSEventRunModal+192
34图形服务0x036f084e GSEventRun+104
35 UIKit 0x01333f0b UIApplicationMain+1225
36 MY项目0x00006612干管+178
37 MyProject 0x00006555启动+53
)
libc++abi.dylib:以NSException类型的未捕获异常终止

提前感谢。

您可以测试它。。尽量避免零。。而不是放一些东西。。。喜欢 [self displayAlertWithMessage:@“请输入有效用户名!”标题:@“Hello”和标签:1]


您需要发布警报视图,以便在函数中编写发布代码

根据崩溃日志,它告诉我,“[UIViewController\u loadViewFromNibNamed:bundle:”无法加载nib文件

但是,在我的项目中,我为UIViewController类创建了一个类别,并重写了
-(id)init
方法。直到ios6,当显示警报时,此类别方法根本不执行,但从ios7开始重写UIViewController的init()方法

因此,我修复了这个问题,在UIViewController类别的init()方法中添加了另一个验证,用于检查类方法是否为UIAlertView,如果是UIAlertView,则只需调用
[super init]而不是执行与视图控制器相关的其他操作

示例代码:

    - (id)init
    {
          NSString *viewControllerName = [NSString stringWithFormat:@"%@",[self class]];
          if([viewControllerName isEqualToString:@"UIAlertView"])
          {
             self = [super init];
          }
          else
          {
             // my stuff
          }
          return self;
    }

你的代码是什么?你看过它在iOS7中实现方式的不同吗?用示例代码更新了问题,请检查..你的Xcode/iOS7安装完成了吗?异常表示无法加载NIB。@Wain,此应用程序是在xcode 4.5中开发的,并已转到应用程序商店。但是,由于这个原因,现在相同的构建正在崩溃。目前,为了调试此问题,我使用的是xcode 5 beta版和ios 7 beta版。可能是某种原因,因为警报试图以与当前视图不同的方向显示。看一看