我有与HMHomeManager增加家庭的问题。 我可以调用函数add
好,但HMHomeManager不返回
func homeManager(manager: HMHomeManager!, didAddHome home: HMHome!) {
println("\(__FUNCTION__)")
}
我相信我已经分配homeManager的代表。 下面是我的代码:
class ViewController: UIViewController, HMHomeManagerDelegate {
var manager: HMHomeManager
required init(coder aDecoder: NSCoder) {
manager = HMHomeManager()
super.init(coder: aDecoder)
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
manager.delegate = self
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// MARK: - Actions
@IBAction func home1Pressed(sender: UIButton) {
manager.addHomeWithName("Home12", completionHandler: {
(home:HMHome!, error:NSError!) -> Void in
if error != nil {
println("error: \(error)")
}
else {
println("no error")
}
})
}
@IBAction func home2Pressed(sender: UIButton) {
manager.addHomeWithName("Home23", completionHandler: {
(home:HMHome!, error:NSError!) -> Void in
if error != nil {
println("error: \(error)")
}
else {
println("no error")
}
})
}
// MARK: - HMHomeManagerDelegate
func homeManagerDidUpdateHomes(manager: HMHomeManager!) {
println("\(__FUNCTION__)")
}
func homeManagerDidUpdatePrimaryHome(manager: HMHomeManager!) {
println("\(__FUNCTION__)")
}
func homeManager(manager: HMHomeManager!, didAddHome home: HMHome!) {
println("\(__FUNCTION__)")
}
func homeManager(manager: HMHomeManager!, didRemoveHome home: HMHome!) {
println("\(__FUNCTION__)")
}
}
需要注意的是:当我第一次运行此代码, homeManagerDidUpdateHomes
叫这证明,我认为homeManager.delegate =自我是正确的
在这段代码,之后我按下按钮1( home1Pressed
触发)和BUTTON2( home1Pressed
触发), home12
和home23
创建。 我知道这是因为我下次运行此代码,输出为:
homeManagerDidUpdateHomes
homes: [[ name = Home1, primary : Yes ], [ name = Home12, primary : No ], [ name = Home23, primary : No ]]
但为什么homeManager(manager: HMHomeManager!, didAddHome home: HMHome!
?当我按下按钮1和按钮2不叫我无法弄清楚,2天。
谢谢,