【问题标题】:Why do I get a Build Error on Tab Bar Tap?为什么我在标签栏点击时出现构建错误?
【发布时间】:2011-07-03 16:59:47
【问题描述】:

我正在创建一个 iPhone iOS 应用程序。我在标签栏控制器中有 3 个标签。当我在 iOS 模拟器中点击标签栏控制器上的第三个标签时,iOS 模拟器消失了,我看到 main.m 文件,上面有一个绿色突出显示:

int retVal = UIApplicationMain(argc, argv, nil, nil);

构建错误指出:线程 1:程序收到信号:SIGABRT

如果我查看屏幕底部的构建输出窗口,我会看到以下文本:

GNU gdb 6.3.50-20050815 (Apple version gdb-1518) (Sat Feb 12 02:52:12 UTC 2011)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin".Attaching to process 4283.
**2011-07-03 12:45:37.114 Cypher Bot[4283:207] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIViewController 0x4e1b190> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key portraitView.'
*** Call stack at first throw:
(
        0   CoreFoundation                      0x00dce5a9 __exceptionPreprocess + 185
        1   libobjc.A.dylib                     0x00f22313 objc_exception_throw + 44
        2   CoreFoundation                      0x00dce4e1 -[NSException raise] + 17
        3   Foundation                          0x007a0677 _NSSetUsingKeyValueSetter + 135
        4   Foundation                          0x007a05e5 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 285
        5   UIKit                               0x0021c30c -[UIRuntimeOutletConnection connect] + 112
        6   CoreFoundation                      0x00d448cf -[NSArray makeObjectsPerformSelector:] + 239
        7   UIKit                               0x0021ad23 -[UINib instantiateWithOwner:options:] + 1041
        8   UIKit                               0x0021cab7 -[NSBundle(UINSBundleAdditions) loadNibNamed:owner:options:] + 168
        9   UIKit                               0x000d2628 -[UIViewController _loadViewFromNibNamed:bundle:] + 70
        10  UIKit                               0x000d0134 -[UIViewController loadView] + 120
        11  UIKit                               0x000d000e -[UIViewController view] + 56
        12  UIKit                               0x000e2f54 -[UITabBarController transitionFromViewController:toViewController:transition:shouldSetSelected:] + 120
        13  UIKit                               0x000e1aaa -[UITabBarController transitionFromViewController:toViewController:] + 64
        14  UIKit                               0x000e38a2 -[UITabBarController _setSelectedViewController:] + 263
        15  UIKit                               0x000e3711 -[UITabBarController _tabBarItemClicked:] + 352
        16  UIKit                               0x000204fd -[UIApplication sendAction:to:from:forEvent:] + 119
        17  UIKit                               0x00222ce6 -[UITabBar _sendAction:withEvent:] + 422
        18  UIKit                               0x000204fd -[UIApplication sendAction:to:from:forEvent:] + 119
        19  UIKit                               0x000b0799 -[UIControl sendAction:to:forEvent:] + 67
        20  UIKit                               0x000b2c2b -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
        21  UIKit                               0x000b0750 -[UIControl sendActionsForControlEvents:] + 49
        22  UIKit                               0x000204fd -[UIApplication sendAction:to:from:forEvent:] + 119
        23  UIKit                               0x000b0799 -[UIControl sendAction:to:forEvent:] + 67
        24  UIKit                               0x000b2c2b -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
        25  UIKit                               0x000b17d8 -[UIControl touchesEnded:withEvent:] + 458
        26  UIKit                               0x00044ded -[UIWindow _sendTouchesForEvent:] + 567
        27  UIKit                               0x00025c37 -[UIApplication sendEvent:] + 447
        28  UIKit                               0x0002af2e _UIApplicationHandleEvent + 7576
        29  GraphicsServices                    0x01007992 PurpleEventCallback + 1550
        30  CoreFoundation                      0x00daf944 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
        31  CoreFoundation                      0x00d0fcf7 __CFRunLoopDoSource1 + 215
        32  CoreFoundation                      0x00d0cf83 __CFRunLoopRun + 979
        33  CoreFoundation                      0x00d0c840 CFRunLoopRunSpecific + 208
        34  CoreFoundation                      0x00d0c761 CFRunLoopRunInMode + 97
        35  GraphicsServices                    0x010061c4 GSEventRunModal + 217
        36  GraphicsServices                    0x01006289 GSEventRun + 115
        37  UIKit                               0x0002ec93 UIApplicationMain + 1160
        38  Cypher Bot                          0x00002889 main + 121
        39  Cypher Bot                          0x00002805 start + 53
        40  ???                                 0x00000001 0x0 + 1
)
terminate called after throwing an instance of 'NSException'
sharedlibrary apply-load-rules all
Current language:  auto; currently objective-c
(gdb)**
>

在此之前我对第三个视图控制器所做的更改是:

  1. 添加横向支持
  2. 添加内存警告事件
  3. 添加允许您打开 SMS 应用程序的功能(我已将其删除,然后我运行了项目但没有任何反应)

编辑: 我已经包含了头文件:

#import <UIKit/UIKit.h>


@interface ThirdViewController : UIViewController {
    IBOutlet UIView *landscapeView;
    IBOutlet UIView *portraitView;

}

@property (nonatomic, retain) IBOutlet UIView *landscapeView;

@property (nonatomic, retain) IBOutlet UIView *portraitView;
@end

@properties 与@synthesize 一起使用,项目中没有错误或警告。

编辑 2:我已经删除了与 PortraitView 和 LandscapeView 相关的所有内容,现在当我运行它并点击更多时,我得到以下信息:

**Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </Users/Spencer/Library/Application Support/iPhone Simulator/4.3.2/Applications/1E0A4C15-2143-442D-A8FC-4AE36CFC90E4/Cypher Bot.app> (loaded)' with name 'ThirdViewController.xib''**

我做错了什么?为什么我不能点击第三个标签?

感谢任何帮助!谢谢!

【问题讨论】:

  • '[ setValue:forUndefinedKey:]: This class is not key value coding-compliant for the key portraitView' 看起来像错误——你在任何地方都使用了一个名为 PortraitView 的变量吗?
  • 是的,我正在使用 IBOutlet UIView *portraitView;我还将它与@property 和@synthesize 一起使用。
  • 我已经检查了我的头文件,它们似乎没有任何问题,xib文件已经链接了它们的所有出口,我不知道我还能做什么。跨度>
  • 再次检查您的 .xib 是否引用了“ThirdViewController”?
  • Xcode 是否可能不允许带有标签栏的横向模式?这就是我可能会收到此错误的原因吗?

标签: objective-c ios ios4 uitabbar build-error


【解决方案1】:

您的 nib 文件似乎试图将某些内容绑定到 UIViewController 上名为 portraitView 的插座,但 UIViewController 没有这样的属性。我猜您需要进入 IB 并将该视图控制器上的类更改为应用程序中应该是的任何自定义 UIViewController 子类。

【讨论】:

    【解决方案2】:

    这是我在 Interface Builder 中的视图。 “文件的所有者”应该设置为相应的视图控制器,在你的情况下,它应该在这里说“ThirdViewController”。确保您链接到正确的视图控制器。

    还要检查将此视图控制器添加到标签栏的代码。你是在初始化 UIViewController 还是 ThirdViewController?确保它是 ThirdViewController。

    【讨论】:

    • 这听起来像是一个很好的解决方案,但它对我不起作用。我在哪里可以找到 Xcode 正在初始化 UIViewController 的地方?
    • 当你创建你的标签栏控制器时,你给它视图控制器作为你的“标签”——这可能发生在你的应用程序启动时。它在您的代码中某处。在这里你必须确保你正在创建一个ThirdViewController and not just a UIViewController`。
    • 布拉德利 我已经尝试了你所建议的一切。我一定做错了什么。我使用了一个选项卡栏模板,添加了一个 UIViewController 子类,然后在它们自己的 nib 和主窗口 nib 和应用程序委托中将它们全部链接在一起。我应该开始一个新项目并将我所有的东西都复制到项目中吗?还有什么我可以做的吗?
    【解决方案3】:

    您可能在将界面构建器中的视图拖到该变量后更改了代码中变量名称的名称,从而导致此类错误。要修复,您必须再次将其拖过来,您可能在该属性的 interfacebuilder 中有一个解释标记。

    【讨论】:

      猜你喜欢
      • 2019-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-13
      • 1970-01-01
      • 2022-10-17
      • 2020-08-12
      • 2020-09-15
      相关资源
      最近更新 更多