菜鸟教程小白 发表于 2022-12-13 11:56:16

ios - Xcode 中的 IB 连接崩溃


                                            <p><p>昨晚我去测试我的 iOS 应用程序时,它在启动时崩溃了。我什至没有研究导致崩溃的 Nib 。无论如何,这是错误代码:</p>

<pre><code>2/29/12 10:32:05.291 AM Safe Flight: *** Terminating app due to uncaught exception &#39;NSUnknownKeyException&#39;, reason: &#39;[&lt;UIApplication 0xdd496f0&gt; setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key Airport1.&#39;
*** First throw call stack:
(0x2873052 0x33add0a 0x2872f11 0x1ae2032 0x1a53f7b 0x1a53eeb 0x1a6ed60 0x136191a 0x2874e1a 0x27de821 0x136046e 0x1362010 0x114214a 0x1142461 0x11417c0 0x1150743 0x11511f8 0x1144aa9 0x37b7fa9 0x28471c5 0x27ac022 0x27aa90a 0x27a9db4 0x27a9ccb 0x11412a7 0x1142a9b 0x3710 0x2f35)
</code></pre>

<p>Airport1 只是一个标签,其中有一个 <strong>正确</strong> 连接到它的 IBOutlet。另外,如果我删除连接,错误只是与下一个有连接的项目有关。</p>

<p>另外,我的 FileOwners 类正确设置为适当的 viewController。</p>

<pre><code>//MasterViewController.h

#import &lt;UIKit/UIKit.h&gt;
#import &#34;MobclixAds.h&#34;

@class DataViewController;
@class EditViewController;
@class SearchViewController;



@interface MasterViewController : UIViewController{

    UILabel *Airport1;
    UILabel *Airport2;
    UILabel *Airport3;
    UILabel *Airport4;
    UILabel *Airport5;
    UILabel *Airport6;
    UILabel *Airport7;
    UILabel *Airport8;
    UILabel *Airport9;
    UIButton *Airport1B;
    UIButton *Airport2B;
    UIButton *Airport3B;
    UIButton *Airport4B;
    UIButton *Airport5B;
    UIButton *Airport6B;
    UIButton *Airport7B;
    UIButton *Airport8B;
    UIButton *Airport9B;

    MobclixAdView* adView;
}

@property (strong, nonatomic) DataViewController *dataViewController;
@property (strong, nonatomic) EditViewController *editViewController;
@property (strong, nonatomic) SearchViewController *searchViewController;


@property (nonatomic, retain) IBOutlet UILabel *Airport1;
@property (nonatomic, retain) IBOutlet UILabel *Airport2;
@property (nonatomic, retain) IBOutlet UILabel *Airport3;
@property (nonatomic, retain) IBOutlet UILabel *Airport4;
@property (nonatomic, retain) IBOutlet UILabel *Airport5;
@property (nonatomic, retain) IBOutlet UILabel *Airport6;
@property (nonatomic, retain) IBOutlet UILabel *Airport7;
@property (nonatomic, retain) IBOutlet UILabel *Airport8;
@property (nonatomic, retain) IBOutlet UILabel *Airport9;
@property (nonatomic, retain) IBOutlet UIButton *Airport1B;
@property (nonatomic, retain) IBOutlet UIButton *Airport2B;
@property (nonatomic, retain) IBOutlet UIButton *Airport3B;
@property (nonatomic, retain) IBOutlet UIButton *Airport4B;
@property (nonatomic, retain) IBOutlet UIButton *Airport5B;
@property (nonatomic, retain) IBOutlet UIButton *Airport6B;
@property (nonatomic, retain) IBOutlet UIButton *Airport7B;
@property (nonatomic, retain) IBOutlet UIButton *Airport8B;
@property (nonatomic, retain) IBOutlet UIButton *Airport9B;

@property(nonatomic,retain) IBOutlet MobclixAdView* adView;


@end
</code></pre>

<p>和</p>

<pre><code>// MasterViewController.m


#import &#34;MasterViewController.h&#34;

#import &#34;DataViewController.h&#34;
#import &#34;EditViewController.h&#34;
#import &#34;SearchViewController.h&#34;



@implementation MasterViewController

@synthesize dataViewController = _dataViewController;
@synthesize editViewController = _editViewController;
@synthesize searchViewController = _searchViewController;



@synthesize Airport1, Airport2, Airport3, Airport4, Airport5, Airport6, Airport7, Airport8, Airport9;
@synthesize Airport1B, Airport2B, Airport3B, Airport4B, Airport5B, Airport6B, Airport7B, Airport8B, Airport9B;
@synthesize adView;


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{

    self = ;
    if (self) {
      self.title = @&#34;Safe Flight&#34;;
      self.navigationItem.backBarButtonItem = [ initWithTitle:@&#34;Back&#34; style:UIBarButtonItemStylePlain target:nil action:nil];
    }
    return self;
}
</code></pre>

<p>我的代码有问题吗?还是 Xcode 本身?我重新启动了 Xcode 和模拟器,甚至做了一个“干净”的构建(听起来会有所帮助......)</p>

<p>谢谢,
安德鲁</p>

<p><strong>编辑</strong>这是我的 AppDelegate,我正在为窗口设置正确的 xib</p>

<pre><code>- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    ;
    self.window = [ initWithFrame:[ bounds]];
    // Override point for customization after application launch.

    MasterViewController *masterViewController = [ initWithNibName:@&#34;MasterViewController&#34; bundle:nil];
    self.navigationController = [ initWithRootViewController:masterViewController];
    self.window.rootViewController = self.navigationController;
    ;
    return YES;

}
</code></pre>

<p>问题解决了!!!</p>

<p>由于一些愚蠢的垃圾邮件过滤器,我无法回答自己的问题...我可以发布问题的图片...但它已修复!</p>

<p>但是这里是问题的链接<a href="http://i.stack.imgur.com/krba5.png" rel="noreferrer noopener nofollow">click here</a> </p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>发现问题!!我现在觉得有点傻;)但无论如何,这是问题的截图!</p>

<p> <a href="/image/krba5.png" rel="noreferrer noopener nofollow"><img src="/image/krba5.png" alt="Devices &#34;Main Interface&#34; had been unintentionally set"/></a> </p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - Xcode 中的 IB 连接崩溃,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/9503536/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/9503536/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - Xcode 中的 IB 连接崩溃