Xcode 协议错误swift

Xcode 协议错误swift,xcode,swift,Xcode,Swift,我是一个编程新手,但问题是ViewController。我使用核心图形创建相应的形状。显示视图控制器以继续显示页面时出错 import UIKit class ViewController: UIViewController,CustomViewDelegate { @IBOutlet weak var sliderSmile: UISlider! override func viewDidLoad() { super.viewDidLoad()

我是一个编程新手,但问题是ViewController。我使用核心图形创建相应的形状。显示视图控制器以继续显示页面时出错

import UIKit

class ViewController: UIViewController,CustomViewDelegate {


    @IBOutlet weak var sliderSmile: UISlider!



    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.


        let defaults:NSUserDefaults = NSUserDefaults.standardUserDefaults()
        let x:CGFloat = CGFloat(defaults.floatForKey("currentImagePosX"))
        let y:CGFloat = CGFloat(defaults.floatForKey("currentImagePosY"))
        //make a point
        //get a ref to the view
        let view = self.view as! CustomView
        //the crucial line
        view.delegate = self

        view.defaultPos.x = x
        view.defaultPos.y = y





    }


    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }



    @IBAction func smileValueChanged(sender: UISlider) {

        let customView = self.view as! CustomView
        customView.setSmile = CGFloat (sender.value)

    }

}
2016-05-19 03:15:30.050 Usmaan [20208:1816738] Unknown class _TtC7Usmaan_8Graphics in Interface Builder file.
2016-05-19 03:15:30.080 Usmaan [20208:1816738] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIViewController 0x7fcc0b7fbc80> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key sliderSmile.'
*** First throw call stack:
(
    0   CoreFoundation                      0x0000000109c5ee65 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x000000010bbc6deb objc_exception_throw + 48
    2   CoreFoundation                      0x0000000109c5eaa9 -[NSException raise] + 9
    3   Foundation                          0x000000010a24f9bb -[NSObject(NSKeyValueCoding) setValue:forKey:] + 288
    4   UIKit                               0x000000010a832320 -[UIViewController setValue:forKey:] + 88
    5   UIKit                               0x000000010aa60f41 -[UIRuntimeOutletConnection connect] + 109
    6   CoreFoundation                      0x0000000109b9f4a0 -[NSArray makeObjectsPerformSelector:] + 224
    7   UIKit                               0x000000010aa5f924 -[UINib instantiateWithOwner:options:] + 1864
    8   UIKit                               0x000000010a838eea -[UIViewController _loadViewFromNibNamed:bundle:] + 381
    9   UIKit                               0x000000010a839816 -[UIViewController loadView] + 178
    10  UIKit                               0x000000010a839b74 -[UIViewController loadViewIfRequired] + 138
    11  UIKit                               0x000000010a83ff4f -[UIViewController __viewWillAppear:] + 120
    12  UIKit                               0x000000010a86fe44 -[UINavigationController _startCustomTransition:] + 1203
    13  UIKit                               0x000000010a88023f -[UINavigationController _startDeferredTransitionIfNeeded:] + 712
    14  UIKit                               0x000000010a8813af -[UINavigationController __viewWillLayoutSubviews] + 57
    15  UIKit                               0x000000010aa27ff7 -[UILayoutContainerView layoutSubviews] + 248
    16  UIKit                               0x000000010a75a4a3 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 703
    17  QuartzCore                          0x000000010f73359a -[CALayer layoutSublayers] + 146
    18  QuartzCore                          0x000000010f727e70 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366
    19  QuartzCore                          0x000000010f727cee _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
    20  QuartzCore                          0x000000010f71c475 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 277
    21  QuartzCore                          0x000000010f749c0a _ZN2CA11Transaction6commitEv + 486
    22  UIKit                               0x000000010a69df7c _UIApplicationHandleEventQueue + 7329
    23  CoreFoundation                      0x0000000109b8aa31 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    24  CoreFoundation                      0x0000000109b8095c __CFRunLoopDoSources0 + 556
    25  CoreFoundation                      0x0000000109b7fe13 __CFRunLoopRun + 867
    26  CoreFoundation                      0x0000000109b7f828 CFRunLoopRunSpecific + 488
    27  GraphicsServices                    0x000000010f1e8ad2 GSEventRunModal + 161
    28  UIKit                               0x000000010a6a3610 UIApplicationMain + 171
    29  Usmaan                              0x00000001096a50dd main + 109
    30  libdyld.dylib                       0x000000010c6d892d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 
委派


显示视图控制器以继续显示页面时出错

import UIKit

class ViewController: UIViewController,CustomViewDelegate {


    @IBOutlet weak var sliderSmile: UISlider!



    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.


        let defaults:NSUserDefaults = NSUserDefaults.standardUserDefaults()
        let x:CGFloat = CGFloat(defaults.floatForKey("currentImagePosX"))
        let y:CGFloat = CGFloat(defaults.floatForKey("currentImagePosY"))
        //make a point
        //get a ref to the view
        let view = self.view as! CustomView
        //the crucial line
        view.delegate = self

        view.defaultPos.x = x
        view.defaultPos.y = y





    }


    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }



    @IBAction func smileValueChanged(sender: UISlider) {

        let customView = self.view as! CustomView
        customView.setSmile = CGFloat (sender.value)

    }

}
2016-05-19 03:15:30.050 Usmaan [20208:1816738] Unknown class _TtC7Usmaan_8Graphics in Interface Builder file.
2016-05-19 03:15:30.080 Usmaan [20208:1816738] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIViewController 0x7fcc0b7fbc80> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key sliderSmile.'
*** First throw call stack:
(
    0   CoreFoundation                      0x0000000109c5ee65 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x000000010bbc6deb objc_exception_throw + 48
    2   CoreFoundation                      0x0000000109c5eaa9 -[NSException raise] + 9
    3   Foundation                          0x000000010a24f9bb -[NSObject(NSKeyValueCoding) setValue:forKey:] + 288
    4   UIKit                               0x000000010a832320 -[UIViewController setValue:forKey:] + 88
    5   UIKit                               0x000000010aa60f41 -[UIRuntimeOutletConnection connect] + 109
    6   CoreFoundation                      0x0000000109b9f4a0 -[NSArray makeObjectsPerformSelector:] + 224
    7   UIKit                               0x000000010aa5f924 -[UINib instantiateWithOwner:options:] + 1864
    8   UIKit                               0x000000010a838eea -[UIViewController _loadViewFromNibNamed:bundle:] + 381
    9   UIKit                               0x000000010a839816 -[UIViewController loadView] + 178
    10  UIKit                               0x000000010a839b74 -[UIViewController loadViewIfRequired] + 138
    11  UIKit                               0x000000010a83ff4f -[UIViewController __viewWillAppear:] + 120
    12  UIKit                               0x000000010a86fe44 -[UINavigationController _startCustomTransition:] + 1203
    13  UIKit                               0x000000010a88023f -[UINavigationController _startDeferredTransitionIfNeeded:] + 712
    14  UIKit                               0x000000010a8813af -[UINavigationController __viewWillLayoutSubviews] + 57
    15  UIKit                               0x000000010aa27ff7 -[UILayoutContainerView layoutSubviews] + 248
    16  UIKit                               0x000000010a75a4a3 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 703
    17  QuartzCore                          0x000000010f73359a -[CALayer layoutSublayers] + 146
    18  QuartzCore                          0x000000010f727e70 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366
    19  QuartzCore                          0x000000010f727cee _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
    20  QuartzCore                          0x000000010f71c475 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 277
    21  QuartzCore                          0x000000010f749c0a _ZN2CA11Transaction6commitEv + 486
    22  UIKit                               0x000000010a69df7c _UIApplicationHandleEventQueue + 7329
    23  CoreFoundation                      0x0000000109b8aa31 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    24  CoreFoundation                      0x0000000109b8095c __CFRunLoopDoSources0 + 556
    25  CoreFoundation                      0x0000000109b7fe13 __CFRunLoopRun + 867
    26  CoreFoundation                      0x0000000109b7f828 CFRunLoopRunSpecific + 488
    27  GraphicsServices                    0x000000010f1e8ad2 GSEventRunModal + 161
    28  UIKit                               0x000000010a6a3610 UIApplicationMain + 171
    29  Usmaan                              0x00000001096a50dd main + 109
    30  libdyld.dylib                       0x000000010c6d892d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 
2016-05-19 03:15:30.050 Usmaan[20208:1816738]未知类界面生成器文件中的图形。
2016-05-19 03:15:30.080 Usmaan[20208:1816738]***由于未捕获的异常“NSUnknownKeyException”而终止应用程序,原因:“[setValue:forUndefinedKey:]:此类不符合密钥滑块英里的键值编码。”
***第一次抛出调用堆栈:
(
0 CoreFoundation 0x0000000109c5ee65例外预处理+165
1 libobjc.A.dylib 0x000000010bbc6deb objc_异常_抛出+48
2 CoreFoundation 0x0000000109c5eaa9-[N异常上升]+9
3基金会0x000 000 010A24F9BB-[ NSKORKS(NSKEY ValueCoDIN)SETValue:FordK::+ 288)
4 UIKit 0x000000010a832320-[UIViewController设置值:forKey:+88
5 UIKit 0x000000010aa60f41-[UIRuntimeOutletConnection connect]+109
6 CoreFoundation 0x0000000109b9f4a0-[NSArray makeObjectsPerformSelector:+224
7 UIKit 0x000000010aa5f924-[UINib实例化所有者:选项:][1864
8 UIKit 0x000000010a838eea-[UIViewController\u loadViewFromNibNamed:bundle:][381
9 UIKit 0x000000010a839816-[UIViewController loadView]+178
10 UIKit 0x000000010a839b74-[UIViewController loadViewIfRequired]+138
11 UIKit 0x000000010a83ff4f-[UIViewController\uuuu视图将出现:][120
12 UIKit 0x000000010a86fe44-[UINavigationController\u startCustomTransition:+1203
13 UIKit 0x000000010a88023f-[UINavigationController\U STARTDEFERREDTRANSION(如果需要):+712
14 UIKit 0x000000010a8813af-[UINavigationController\uuu视图将布局子视图]+57
15 UIKit 0x000000010aa27ff7-[UILayoutContainerView布局子视图]+248
16 UIKit 0x000000010a75a4a3-[UIView(CALayerDelegate)布局层的子层:+703
17夸脱核心0x000000010f73359a-[CALayer布局子层]+146
18夸脱核心0x000000010f727e70(如果需要)Zn2Ca5层布局交易+366
19 QuartzCore 0x000000010f727cee\u ZN2CA58层布局和显示(如果需要)PNS\u 11事务+24
20夸脱核心0x000000010f71c475_ZN2CA7Context18提交交易PNS_11交易+277
21夸脱核心0x000000010f749c0a\u Zn2CA11交易承诺+486
22 UIKit 0x000000010a69df7c _UI应用程序手柄VENTQUEUE+7329
23 CoreFoundation 0x0000000109b8aa31 \uuuuu CFRUNLOOP \uu正在调用\uu OUT \uu以执行\uuu函数\uuuuu+17
24 CoreFoundation 0x0000000109b8095c\uu CFRunLoopDoSources0+556
25 CoreFoundation 0x0000000109b7fe13\uuu CFRunLoopRun+867
26 CoreFoundation 0x0000000109b7f828 CFRunLoopRunSpecific+488
27图形服务0x000000010f1e8ad2 GSEventRunModal+161
28 UIKit 0x000000010a6a3610 UIApplicationMain+171
29 Usmaan 0x00000001096a50dd干管+109
30 libdyld.dylib 0x000000010c6d892d开始+1
)
libc++abi.dylib:以NSException类型的未捕获异常终止
(lldb)

您需要在视图控制器中实现
更新图像位置。否则,控制器不符合协议中规定的方法和属性。有关更多详细信息,请参阅协议文档:

请向我们显示已完成的委派…………您的视图控制器不符合
CustomViewDelegate
,因为您尚未实现
UpdateImage Position
。谢谢。显示核心图形时也会出现异常错误。转到ViewController屏幕谢谢。显示核心图形时也会出现异常错误。转到ViewController屏幕。应用程序委托将显示一个error@UsmaanGill