我想在该项目中安装此示例SegmentedControl,然后转到老式wai(将HMSegmentedControl.h和HMSegmentedControl.m添加到我的项目中。)在MyViewController.n和MyViewController中创建ViewController(来自示例项目)的代码并将其放入.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"]]];

最佳答案

您已将Map类设置为情节提要或xib中的任何对象。

删除Map类查看图片

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

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

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



现在,您在以下行出现错误:

 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。检查包中的所有图像。

关于ios - 不能与Storyboard一起使用HMSegmentedControl,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29234656/

10-12 00:26