当我运行它,我得到错误
Terminating app due to uncaught exception
‘NSInternalinconsistencyException’,reason: ‘-[UIVIEwController
_loadVIEwFromNibnamed:bundle:] loaded the “…” nib but the vIEw outlet was not set.’
所以我打开了我的nib文件,看看“文件的所有者”,我看到这个视图根本不显示出来.
对于我的旧视图控制器(目标c),视图插座确实显示.
在我的Swift视图控制器中,我试图从UIVIEwController中重写“vIEw”变量,以强制它是一个@IBOutlet,但是它抱怨UIVIEw类型的“vIEw”变量,UIVIEw?抱怨,并抱怨UIVIEw !
这是简化版本
我的AppDelegate.h
#import <UIKit/UIKit.h>@class MyVIEwController;@class MyVIEwControllerSwift;@interface MSAppDelegate : UIResponder <UIApplicationDelegate>{}@property (strong,nonatomic) UIWindow *window;@property (strong,nonatomic) UIVIEwController *vIEwController;@end
AppDelegate.m
#import "MyAppDelegate.h"#import "MyVIEwController.h"#import "MySwift-Swift.h"#import <UIKit/UIKit.h>@implementation MyAppDelegatestatic BOol USE_SWIFT_VIEW_CONTRolLER = YES;- (voID)dealloc{ [_window release]; [_vIEwController release]; [super dealloc];}- (BOol)application:(UIApplication *)application dIDFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; // OverrIDe point for customization after application launch. ID vIEwControllerPtr = nil; if(USE_SWIFT_VIEW_CONTRolLER) { vIEwControllerPtr = [MyVIEwControllerSwift alloc]; } else { vIEwControllerPtr = [MyVIEwController alloc]; } UIVIEwController* vController = nil; if(USE_SWIFT_VIEW_CONTRolLER) { vController = [[vIEwControllerPtr initWithNibname:@"MyVIEwControllerSwift" bundle:nil] autorelease]; } else { vController = [[vIEwControllerPtr initWithNibname:@"MyVIEwController" bundle:nil] autorelease]; } self.vIEwController = vController; self.window.rootVIEwController = self.vIEwController; [self.window makeKeyAndVisible]; return YES;}
VIEwController.swift
import Foundationimport AVFoundation@objc class MyVIEwControllerSwift : UIKit.UIVIEwController { var player : AVFoundation.AVAudioPlayer?; @IBOutlet weak var myTextVIEw : UITextVIEw!; required init(coder aDecoder : NSCoder) { super.init(coder:aDecoder); } overrIDe init(nibname nibnameOrNil: String?,bundle nibBundleOrNil: NSBundle?) { super.init(nibname:nibnameOrNil,bundle:nibBundleOrNil); } overrIDe func vIEwDIDLoad() { super.vIEwDIDLoad(); println("Using MyVIEwControllerSwift"); } deinit { //Todo }}
我需要做什么来让我的视图显示?
谢谢.
(是的,这是一个类似于Loaded nib but the view outlet was not set – new to InterfaceBuilder的问题,但是视图没有出现.)
解决方法 >首先在你的nib文件中设置自定义类(文件所有者 – >第三个图标 – >自定义类:YourVIEwController)
>第二 – 文件所有者中的最后一个图标 – >链接(拖动)“视图”属性到接口视图
像你这样启动你的VIEwController:
YourVIEwController(nibname: "YourVIEwname",bundle: nil)
它会奏效不要对VIEw进行任何 *** 作.
总结以上是内存溢出为你收集整理的ios – 加载笔尖,但视图插座未设置 – Swift版全部内容,希望文章能够帮你解决ios – 加载笔尖,但视图插座未设置 – Swift版所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)