不使用故事板来处理HMSegmentedControl

时间:2015-03-24 14:02:26

标签: ios objective-c

我想在我的项目中安装这个示例SegmentedControl,我去了老式的wai(将HMSegmentedControl.h和HMSegmentedControl.m添加到我的项目中。)创建并将ViewController的代码(来自示例项目)放在MyViewController中。 n和MyViewController.m,在发布后出现了这样的错误 - 如何解决?

    2015-03-24 16:50:34.170 gfhfgh[455:7040] Unknown class Map in Interface Builder file.
2015-03-24 16:50:34.782 gfhfgh[455:7040] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[0]'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010f8baa75 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x000000010f553bb7 objc_exception_throw + 45
    2   CoreFoundation                      0x000000010f780c78 -[__NSPlaceholderArray initWithObjects:count:] + 360
    3   CoreFoundation                      0x000000010f7dfbe4 +[NSArray arrayWithObjects:count:] + 52
    4   gfhfgh                              0x000000010d859963 -[Map2ViewController viewDidLoad] + 2435
    5   UIKit                               0x000000010e3b4580 -[UIViewController loadViewIfRequired] + 738
    6   UIKit                               0x000000010e3b477e -[UIViewController view] + 27
    7   UIKit                               0x000000010e957f4e -[_UIFullscreenPresentationController _setPresentedViewController:] + 65
    8   UIKit                               0x000000010e38fd69 -[UIPresentationController initWithPresentedViewController:presentingViewController:] + 105
    9   UIKit                               0x000000010e3c0531 -[UIViewController _presentViewController:withAnimationController:completion:] + 1746
    10  UIKit                               0x000000010e3c2871 __62-[UIViewController presentViewController:animated:completion:]_block_invoke + 132
    11  UIKit                               0x000000010e3c2795 -[UIViewController presentViewController:animated:completion:] + 229
    12  UIKit                               0x000000010e28fa22 -[UIApplication sendAction:to:from:forEvent:] + 75
    13  UIKit                               0x000000010e396e50 -[UIControl _sendActionsForEvents:withEvent:] + 467
    14  UIKit                               0x000000010e39621f -[UIControl touchesEnded:withEvent:] + 522
    15  UIKit                               0x000000010e2d5b68 -[UIWindow _sendTouchesForEvent:] + 735
    16  UIKit                               0x000000010e2d6493 -[UIWindow sendEvent:] + 683
    17  UIKit                               0x000000010e2a2fb1 -[UIApplication sendEvent:] + 246
    18  UIKit                               0x000000010e2b0227 _UIApplicationHandleEventFromQueueEvent + 17700
    19  UIKit                               0x000000010e28b23c _UIApplicationHandleEventQueue + 2066
    20  CoreFoundation                      0x000000010f7efc91 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    21  CoreFoundation                      0x000000010f7e5b5d __CFRunLoopDoSources0 + 269
    22  CoreFoundation                      0x000000010f7e5194 __CFRunLoopRun + 868
    23  CoreFoundation                      0x000000010f7e4bc6 CFRunLoopRunSpecific + 470
    24  GraphicsServices                    0x0000000111652a58 GSEventRunModal + 161
    25  UIKit                               0x000000010e28e580 UIApplicationMain + 1282
    26  gfhfgh                              0x000000010d8769b3 main + 115
    27  libdyld.dylib                       0x0000000111181145 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

删除发生类卡错误后

    2015-03-24 17:41:22.081 gfhfgh[576:7945] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[0]'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010eaa6a75 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x000000010e73fbb7 objc_exception_throw + 45
    2   CoreFoundation                      0x000000010e96cc78 -[__NSPlaceholderArray initWithObjects:count:] + 360
    3   CoreFoundation                      0x000000010e9cbbe4 +[NSArray arrayWithObjects:count:] + 52
    4   gfhfgh                              0x000000010ca45963 -[Map2ViewController viewDidLoad] + 2435
    5   UIKit                               0x000000010d5a0580 -[UIViewController loadViewIfRequired] + 738
    6   UIKit                               0x000000010d5a077e -[UIViewController view] + 27
    7   UIKit                               0x000000010db43f4e -[_UIFullscreenPresentationController _setPresentedViewController:] + 65
    8   UIKit                               0x000000010d57bd69 -[UIPresentationController initWithPresentedViewController:presentingViewController:] + 105
    9   UIKit                               0x000000010d5ac531 -[UIViewController _presentViewController:withAnimationController:completion:] + 1746
    10  UIKit                               0x000000010d5ae871 __62-[UIViewController presentViewController:animated:completion:]_block_invoke + 132
    11  UIKit                               0x000000010d5ae795 -[UIViewController presentViewController:animated:completion:] + 229
    12  UIKit                               0x000000010d47ba22 -[UIApplication sendAction:to:from:forEvent:] + 75
    13  UIKit                               0x000000010d582e50 -[UIControl _sendActionsForEvents:withEvent:] + 467
    14  UIKit                               0x000000010d58221f -[UIControl touchesEnded:withEvent:] + 522
    15  UIKit                               0x000000010d4c1b68 -[UIWindow _sendTouchesForEvent:] + 735
    16  UIKit                               0x000000010d4c2493 -[UIWindow sendEvent:] + 683
    17  UIKit                               0x000000010d48efb1 -[UIApplication sendEvent:] + 246
    18  UIKit                               0x000000010d49c227 _UIApplicationHandleEventFromQueueEvent + 17700
    19  UIKit                               0x000000010d47723c _UIApplicationHandleEventQueue + 2066
    20  CoreFoundation                      0x000000010e9dbc91 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    21  CoreFoundation                      0x000000010e9d1b5d __CFRunLoopDoSources0 + 269
    22  CoreFoundation                      0x000000010e9d1194 __CFRunLoopRun + 868
    23  CoreFoundation                      0x000000010e9d0bc6 CFRunLoopRunSpecific + 470
    24  GraphicsServices                    0x000000011083ea58 GSEventRunModal + 161
    25  UIKit                               0x000000010d47a580 UIApplicationMain + 1282
    26  gfhfgh                              0x000000010ca629b3 main + 115
    27  libdyld.dylib                       0x000000011036d145 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

编辑: 以绿色突出显示此行,应用程序停止,第1行:断点1.1

HMSegmentedControl *segmentedControl2 = [[HMSegmentedControl alloc] initWithSectionImages:@[[UIImage imageNamed:@"1"], [UIImage imageNamed:@"2"], [UIImage imageNamed:@"3"], [UIImage imageNamed:@"4"]] sectionSelectedImages:@[[UIImage imageNamed:@"1-selected"], [UIImage imageNamed:@"2-selected"], [UIImage imageNamed:@"3-selected"], [UIImage imageNamed:@"4-selected"]]];

2 个答案:

答案 0 :(得分:2)

您已将Map类设置为storyboard或xib中的任何对象。

删除Map课程,请参阅图片

编辑:现在您有一个跟随错误,它告诉您正在尝试将nil对象插入数组或字典。

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[0]'

要跟踪此错误,请添加异常断点并运行该项目。 (如下图所示)

enter image description here

现在您在以下行中遇到错误:

 HMSegmentedControl *segmentedControl2 = [[HMSegmentedControl alloc] initWithSectionImages:@[[UIImage imageNamed:@"1"], [UIImage imageNamed:@"2"], [UIImage imageNamed:@"3"], [UIImage imageNamed:@"4"]] sectionSelectedImages:@[[UIImage imageNamed:@"1-selected"], [UIImage imageNamed:@"2-selected"], [UIImage imageNamed:@"3-selected"], [UIImage imageNamed:@"4-selected"]]];

这意味着您的一张图片为nil。检查捆绑中的所有图像。

答案 1 :(得分:0)

您似乎有一个未知的班级Map in your interface builder。它是此View Controller的UIView

VC

您应该删除Map(如N J Gadhiya所示)或创建一个继承自Map的课程UIView,具体取决于您要执行的操作。

您是否在故事板/ xib中添加了UIMapView?如果是这样,您需要向继承自Map的项目UIMapView添加一个类。

如果您已将另一个项目定义为具有类Map,那么您必须创建一个继承自该元素来自的类型的类Map