所以我想詢問用戶,通過板材,事中模態對話框:設置第一響應模態表
class MyTextView : NSTextView {
override func viewWillDraw() {
dispatch_async(dispatch_get_main_queue()) {
self.window?.makeFirstResponder(self)
}
}
}
private func requestNotification() {
let alert = NSAlert()
alert.alertStyle = NSAlertStyle.InformationalAlertStyle
alert.messageText = "Enter your email address"
let urlField = MyTextView.init(frame: NSMakeRect(0,0,300,28))
let urlScroll = NSScrollView.init(frame: NSMakeRect(0,0,300,28))
urlScroll.hasVerticalScroller = true
urlScroll.autohidesScrollers = true
urlField.drawsBackground = true
urlField.editable = true
urlScroll.documentView = urlField
alert.accessoryView = urlScroll
alert.addButtonWithTitle("Send")
alert.addButtonWithTitle("Cancel")
alert.beginSheetModalForWindow(self.window!, completionHandler: { response in
if response == NSAlertFirstButtonReturn {
// Send
let view = (alert.accessoryView as! NSScrollView).documentView as! NSTextView
let text = view.string! as String
self.webViewController.loadAlmostURL(text)
}
})
}
其功能好了很多然後用的NSTextField嘗試。
至少交互從入口開始,但是,我想邊界文本視圖?
那麼,子類的NSTextField我可以把它的第一個響應者,但編輯重疊喜歡的東西是不是正確加載;我會用這個更新原件。 – slashlos
改爲使用NSTextView;然而這會導致需要將其嵌入到滾動視圖中的另一個問題,這又需要約束來允許垂直滾動出現。 – slashlos