gpt4 book ai didi

objective-c - 使 Swift 类可用于 Interface Builder

转载 作者:可可西里 更新时间:2023-10-31 23:45:48 25 4
gpt4 key购买 nike

<分区>

我有一个 XCode 项目,我是用 Objective-C 开发的,但现在使用 Swift 我有几个类保存为 .swift 文件。当我在 Interface Builder 中将这些作为自定义类引用时,它们不起作用,并且我收到该类不存在的错误消息。

在弥合两者之间的差距方面,我缺少什么?我有使 Objective-C 可用于 Swift 的头文件,但不确定其他方式

谢谢

2014-07-08 20:18:07.463 FoodForTeeth[22030:70b] Unknown class SecondViewController in Interface Builder file.
2014-07-08 20:18:07.496 FoodForTeeth[22030:70b] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIViewController 0x8c85390> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key date.'
*** First throw call stack:
(
0 CoreFoundation 0x01acf5e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x018528b6 objc_exception_throw + 44
2 CoreFoundation 0x01b5f6a1 -[NSException raise] + 17
3 Foundation 0x01513c2e -[NSObject(NSKeyValueCoding) setValue:forUndefinedKey:] + 282
4 Foundation 0x0147ff3b _NSSetUsingKeyValueSetter + 88
5 Foundation 0x0147f493 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 267
6 Foundation 0x014e194a -[NSObject(NSKeyValueCoding) setValue:forKeyPath:] + 412
7 UIKit 0x00866cd5 -[UIRuntimeOutletConnection connect] + 106
8 libobjc.A.dylib 0x018647d2 -[NSObject performSelector:] + 62
9 CoreFoundation 0x01acab6a -[NSArray makeObjectsPerformSelector:] + 314
10 UIKit 0x0086582e -[UINib instantiateWithOwner:options:] + 1417
11 UIKit 0x006d7c95 -[UIViewController _loadViewFromNibNamed:bundle:] + 280
12 UIKit 0x006d843d -[UIViewController loadView] + 302
13 UIKit 0x006d873e -[UIViewController loadViewIfRequired] + 78
14 UIKit 0x006d8c44 -[UIViewController view] + 35
15 UIKit 0x006f2a72 -[UINavigationController _startCustomTransition:] + 778
16 UIKit 0x006ff757 -[UINavigationController _startDeferredTransitionIfNeeded:] + 688
17 UIKit 0x00700349 -[UINavigationController __viewWillLayoutSubviews] + 57
18 UIKit 0x0083939d -[UILayoutContainerView layoutSubviews] + 213
19 UIKit 0x0062fdd7 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355
20 libobjc.A.dylib 0x0186481f -[NSObject performSelector:withObject:] + 70
21 QuartzCore 0x045ab72a -[CALayer layoutSublayers] + 148
22 QuartzCore 0x0459f514 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
23 QuartzCore 0x0459f380 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 26
24 QuartzCore 0x04507156 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 294
25 QuartzCore 0x045084e1 _ZN2CA11Transaction6commitEv + 393
26 QuartzCore 0x04508bb4 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
27 CoreFoundation 0x01a9753e __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
28 CoreFoundation 0x01a9748f __CFRunLoopDoObservers + 399
29 CoreFoundation 0x01a753b4 __CFRunLoopRun + 1076
30 CoreFoundation 0x01a74b33 CFRunLoopRunSpecific + 467
31 CoreFoundation 0x01a7494b CFRunLoopRunInMode + 123
32 GraphicsServices 0x02ebc9d7 GSEventRunModal + 192
33 GraphicsServices 0x02ebc7fe GSEventRun + 104
34 UIKit 0x005c594b UIApplicationMain + 1225
35 FoodForTeeth 0x0001c42d main + 141
36 libdyld.dylib 0x02b5e701 start + 1
37 ??? 0x00000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)

SecondViewController.swift

import UIkit
import CoreData

@objc(SecondViewController) class SecondViewController: UIViewController, UITextFieldDelegate {

@IBOutlet var txtTask: UITextField!
@IBOutlet var txtDesc: UITextField!
@IBOutlet var date: UIDatePicker!
@IBOutlet var dateDisplayLabel: UILabel!


override func viewDidLoad() {
super.viewDidLoad()

configureDatePicker()
}

func configureDatePicker() {

date.addTarget(self, action: "updateDatePickerLabel", forControlEvents: .ValueChanged)

updateDatePickerLabel()
}

func updateDatePickerLabel() {
dateDisplayLabel.text = dateFormatter.stringFromDate(date.date)
}

@lazy var dateFormatter: NSDateFormatter = {
let dateFormatter = NSDateFormatter()

dateFormatter.timeStyle = .ShortStyle

return dateFormatter
}()


override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}

//Events
@IBAction func btnAddTask_Click(sender: UIButton){

let appDel: foodforteethAppDelegate = UIApplication.sharedApplication().delegate as foodforteethAppDelegate
let context:NSManagedObjectContext = appDel.managedObjectContext

let ent = NSEntityDescription.entityForName("Food", inManagedObjectContext: context)

var newFood = food(entity: ent, insertIntoManagedObjectContext: context)
newFood.foodname = txtTask.text
newFood.date = dateFormatter.stringFromDate(date.date)

context.save(nil)


/*
taskMgr.addTask(txtTask.text, desc: dateFormatter.stringFromDate(date.date));

self.view.endEditing(true)


txtTask.text = ""
//txtDesc.text = ""
//self.tabBarController.selectedIndex = 0;*/

self.navigationController.popViewControllerAnimated(true)

}

//iOS touch functions
override func touchesBegan(touches: NSSet!, withEvent event: UIEvent!){
self.view.endEditing(true)
}


func textFieldShouldReturn(textField: UITextField!) -> Bool {
textField.resignFirstResponder();
return true
}

}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com