gpt4 book ai didi

ios - 今天扩展与 NSNotificationCenter 崩溃

转载 作者:行者123 更新时间:2023-11-28 09:14:56 25 4
gpt4 key购买 nike

我正在创建一个扩展/缩小以节省空间的今日扩展。在通知中心,但我在使用 NSNotificationCenter 时遇到了问题。如果我调用 visibility() 函数, View 会正常收缩和增长,但如果我尝试发布通知,扩展会失败并尝试重新加载(至少第一次,第二次扩展只是说“无法加载”。这是为什么?

var NSNotificationDidChoose = "NSNotificationDidChoose"    
@IBOutlet var tableView: UITableView!
@IBOutlet var activityIndicator: UIActivityIndicatorView!
@IBAction func shrink(sender: AnyObject) {
//visibility(["bool":false])works fine here
NSNotificationCenter.defaultCenter().postNotificationName(NSNotificationDidChoose, object: nil, userInfo: ["bool":false])
//Crashes and the extension reloads


}
@IBAction func unshrink(sender: AnyObject) {
//visibility(["bool":true]) works fine here
NSNotificationCenter.defaultCenter().postNotificationName(NSNotificationDidChoose, object: nil, userInfo: ["bool":true])
//Crashes and the extension reloads
}
@IBOutlet var buttonview: UIView!

func visibility(boole:[NSObject:AnyObject]) {
var bool = boole["bool"] as Bool
println(bool)
tableView.hidden = !bool
activityIndicator.hidden = !bool
if bool {
self.preferredContentSize = CGSize(width: 350, height: 420)
} else {
self.preferredContentSize = CGSize(width: 350, height: buttonview.frame.height+25)
}
}
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(true)
NSNotificationCenter.defaultCenter().addObserver(self, selector: "visibility:", name: NSNotificationDidChoose, object: nil)
}

最佳答案

通知方法的参数是NSNotification。试试这个。

func visibility(notif: NSNotification) {
let boole = notif.userInfo!
var bool = boole["bool"] as Bool
....
}

关于ios - 今天扩展与 NSNotificationCenter 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28143945/

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