UIApplicationMain在xcode中崩溃

时间:2014-01-07 09:47:50

标签: ios iphone objective-c xcode

我的应用程序崩溃为

#import <UIKit/UIKit.h>

int main(int argc, char *argv[])
{

    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    int retVal = UIApplicationMain(argc, argv, nil, nil);      //Thread 1:signal SIGABRT
    [pool release];
    return retVal;

    /*
    int retVal = 0;
    @autoreleasepool {
        NSString *classString = NSStringFromClass([gTalkAppDelegate class]);
        @try {
            retVal = UIApplicationMain(argc, argv, nil, classString);
        }
        @catch (NSException *exception) {
            NSLog(@"Exception - %@",[exception description]);
            exit(EXIT_FAILURE);
        }
    }
    return retVal;
    */
}


2014-01-07 15:41:25.881 testproject[28812:70b] -[__NSCFConstantString countByEnumeratingWithState:objects:count:]: unrecognized selector sent to instance 0x281d184
2014-01-07 15:41:25.973 testproject[28812:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFConstantString countByEnumeratingWithState:objects:count:]: unrecognized selector sent to instance 0x281d184'
*** First throw call stack:
(
    0   CoreFoundation                      0x026d75e4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x01c028b6 objc_exception_throw + 44
    2   CoreFoundation                      0x02774903 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
    3   CoreFoundation                      0x026c790b ___forwarding___ + 1019
    4   CoreFoundation                      0x026c74ee _CF_forwarding_prep_0 + 14
    5   testproject                        0x0000e7cd -[SecondViewController showData] + 1837
    6   testproject                        0x0000829d -[SecondViewController viewDidAppear:] + 1261
    7   UIKit                               0x0087ac48 -[UIViewController _setViewAppearState:isAnimating:] + 497
    8   UIKit                               0x0087b1d7 -[UIViewController __viewDidAppear:] + 146
    9   UIKit                               0x00898fca -[UINavigationController viewDidAppear:] + 191
    10  UIKit                               0x0087ac48 -[UIViewController _setViewAppearState:isAnimating:] + 497
    11  UIKit                               0x0087b1d7 -[UIViewController __viewDidAppear:] + 146
    12  UIKit                               0x008a827b -[UITabBarController viewDidAppear:] + 113
    13  UIKit                               0x0087ac48 -[UIViewController _setViewAppearState:isAnimating:] + 497
    14  UIKit                               0x0087b1d7 -[UIViewController __viewDidAppear:] + 146
    15  UIKit                               0x0087cb9f __64-[UIViewController viewDidMoveToWindow:shouldAppearOrDisappear:]_block_invoke + 44
    16  UIKit                               0x0087b56a -[UIViewController _executeAfterAppearanceBlock] + 63
    17  UIKit                               0x007801a9 ___afterCACommitHandler_block_invoke_2 + 33
    18  UIKit                               0x0078012e _applyBlockToCFArrayCopiedToStack + 403
    19  UIKit                               0x0077ff7e _afterCACommitHandler + 568
    20  CoreFoundation                      0x0269f4ce __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
    21  CoreFoundation                      0x0269f41f __CFRunLoopDoObservers + 399
    22  CoreFoundation                      0x0267d344 __CFRunLoopRun + 1076
    23  CoreFoundation                      0x0267cac3 CFRunLoopRunSpecific + 467
    24  CoreFoundation                      0x0267c8db CFRunLoopRunInMode + 123
    25  GraphicsServices                    0x035e09e2 GSEventRunModal + 192
    26  GraphicsServices                    0x035e0809 GSEventRun + 104
    27  UIKit                               0x00763d3b UIApplicationMain + 1225
    28  testproject                        0x0000213d main + 125
    29  testproject                        0x000020b5 start + 53
    30  ???                                 0x00000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

如何修复它。

2 个答案:

答案 0 :(得分:3)

通过您的堆栈跟踪,您可以看到在viewDidAppear中您调用了一个名为showData的方法,可以从下面两行看到。

5   gtalkhotdial   0x0000e7cd -[SecondViewController showData] + 1837
6   gtalkhotdial   0x0000829d -[SecondViewController viewDidAppear:] + 1261

在这个showData方法中,你调用了一些东西(不幸的是我们无法分辨出什么)试图调用-[__NSCFConstantString countByEnumeratingWithState:objects:count:]:以及该对象是什么,它没有这个方法。要告诉你更多信息,我们需要查看方法showData中的内容。但你的崩溃显然正在那里发生。如果你知道其他什么,请分享该方法的实现。

答案 1 :(得分:0)

查看堆栈跟踪,行

 2   CoreFoundation                      0x02774903 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275

5   gtalkhotdial                        0x0000e7cd -[SecondViewController showData] + 1837

应该帮助你