我有这个代码,用于响应强制触摸后点击的菜单项:
class InterfaceController: WKInterfaceController {
override init() {
super.init()
self.addMenuItemWithItemIcon(WKMenuItemIcon.Pause, title: "Pause", action: Selector("test"))
}
func test() {
print("test")
}
}
Run Code Online (Sandbox Code Playgroud)
当我强行触摸时,会出现菜单.当我点击"暂停"按钮时,test()不会被调用.
任何想法为什么会这样?
我正在制作一个Apple Watch应用程序,我想根据初始条件设置不同的根视图控制器.
我不能直接设置WatchKit rootInterfaceController,因为它是一个只读属性,但通过检查Apple文档,他们说可以"在启动序列完成之前"设置它.
你有一个很好的建议去做吗?也许通过故事板?
我在Xcode中收到此错误.
2018-02-26 07:13:22.326888-0500 Watch Extension[1298:2691330] [View] First responder warning: '<SPInterfacePicker: 0x14dc1740; frame = (76 0; 58 44); gestureRecognizers = <NSArray: 0x14dcd8a0>; layer = <CALayer: 0x14dc1910>>' rejected resignFirstResponder when being removed from hierarchy
我InterfaceController有4个WkInterfacePickerS和它似乎像这个错误可能与呈现警报(当用户保存数据),但我不知道.
有没有人见过这个?
我的代码:
if successSaving == true {
DispatchQueue.main.async {
WKInterfaceDevice.current().play(.success)
self.showSuccessAlertWith(message: "Workout Saved, Stats Added.")
}
func showSuccessAlertWith(message: String){
let action1 = WKAlertAction(title: "OK", style: .default) {
WKInterfaceController.reloadRootPageControllers(withNames: ["InterfaceController"],
contexts: nil,
orientation: .vertical,
pageIndex: 0)
}
presentAlert(withTitle: "Success", message: message, preferredStyle: .alert, actions: [action1])
} …Run Code Online (Sandbox Code Playgroud) 我使用 setTitle() 在控制器的左上角(与时钟对齐)显示自定义文本。但升级到watchOS 10后,标题显示在右侧、时钟下方,将所有设计都推倒了。
是否有解决方法可以使标题的行为与旧版本相同?
有没有办法避免这种行为。当应用程序进入前台时,我用新数据更新手表应用程序界面。这不是建议的时间吗?视图控制器是基于页面的导航模式中的第一个页面。
我正在使用 WatchKit,我有一个简单的界面,只有一个表,但我只用几行代码就得到了一个错误,也许我忘记了一些非常基本的东西。
我的界面:
表内的行具有标识符:

和自定义类:

控制器由以下代码实现:
import WatchKit
import Foundation
class ActiveListController: WKInterfaceController
{
@IBOutlet weak var tableView: WKInterfaceTable!
override func awakeWithContext(context: AnyObject?)
{
super.awakeWithContext(context)
loadData()
}
override func willActivate()
{
// This method is called when watch view controller is about to be visible to user
super.willActivate()
}
override func didDeactivate()
{
// This method is called when watch view controller is no longer visible
super.didDeactivate()
}
func loadData()
{
tableView.setNumberOfRows(10, withRowType: "ItemRow") // GET ERROR
for index in …Run Code Online (Sandbox Code Playgroud) 我在WKExtensionDelegate和WKInterfaceController上都添加了日志。这是我在Watch OS Simulator中启动和退出应用程序时得到的信息。(模拟器正在运行watchOS 4.2)
第1步:在首次启动该应用程序时,以下是我看到的日志:
第2步:在我处于应用程序状态时,按下主屏幕按钮(Cmd-Shift-h)后,我会得到以下日志:
步骤3:我从应用程序屏幕再次启动我的应用程序(从复杂的应用程序启动时也是如此)
问题1:在步骤2中,也didDeactivate被调用2次,willActivate并且didAppear由于某种原因被调用。我希望didDeactivate被称为一次。有人知道为什么会这样吗?
问题2:在第3步中,willActivate我期望didAppear会被致电。为什么不叫?
在我们用 Objective-C(不是 SwiftUI)开发的现有 watchOS 应用程序中,我们曾经设置应用程序每个屏幕的标题属性(WKInterfaceController 类)(在 Interface Builder 或 Objective-C 代码中)。
标题显示在左上角(时间显示在右上角) => 两条信息在同一行,为界面留下了很大一部分屏幕,无需滚动
我们已经为 watchOS 10 构建了应用程序(使用 watchOS 10 Beta 7 SDK),并在 Apple Watch 上的 watch OS10 Beta 7 上进行了测试 => 标题显示在右侧,时间后面 => 它使用两行和界面可用于应用程序屏幕的数量大大减少。
是否有任何解决方案可以将标题设置为向左对齐,以便使其与时间显示在同一行,就像在 watchOS 9 上一样?
预先感谢您的回答
此致。
我正在使用Xcode Version 7.0 beta 3.当试图使用WKInterfacePicker时,我收到一个错误.
这是我的WKInterfaceController的代码:
import WatchKit
import Foundation
class RBWelcomeVC: WKInterfaceController {
@IBOutlet var pickerAllWorkouts: WKInterfacePicker!
override func awakeWithContext(context: AnyObject?) {
super.awakeWithContext(context)
// Configure interface objects here.
}
override func willActivate() {
// This method is called when watch view controller is about to be visible to user
super.willActivate()
}
override func didDeactivate() {
// This method is called when watch view controller is no longer visible
super.didDeactivate()
}
}
Run Code Online (Sandbox Code Playgroud)
注意我的IBOutlet.当我通过控制从故事板拖动创建它时.它创建了插座并立即将此错误:
Use of undeclared type 'WKInterfacePicker'
Run Code Online (Sandbox Code Playgroud)
由于这不起作用,我尝试手动创建插座.我键入:
@IBOutlet …Run Code Online (Sandbox Code Playgroud) 我有一个WKInterfaceController,我添加了一个表如下:
// .h
@interface InterfaceController : WKInterfaceController
@property (weak, nonatomic) IBOutlet WKInterfaceTable *table;
@end
// .m
- (void)table:(WKInterfaceTable *)table didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
NSLog(@"did select");
}
- (void)table:(WKInterfaceTable *)table
didSelectRowAtIndex:(NSInteger)rowIndex{
NSLog(@"did select new");
}
Run Code Online (Sandbox Code Playgroud)
但是这两种方法都没有被调用.我无法找到WKInterfaceTable的任何协议声明,也没有找到表上的任何委托属性.
这里有什么我想念的吗?
我有一个WKInterfaceController,WKInterfaceTable其中列出了用户在我的应用中记录的一些事件。
用户可以点击表的一行以查看有关该事件的更多详细信息。为此,我覆盖contextForSegue(withIdentifier:in:rowIndex:)了WKInterfaceController包含该表的,因此,轻按一行以一种WKInterfaceController名为的新形式呈现该行的详细视图EventDetailController。
该modal演示文稿在情节提要中定义。我无法使用push演示文稿,因为WKInterfaceController带有的WKInterfaceTable是WKInterfaceController应用程序顶层多个实例之间的页面。
在中EventDetailController,有一个Delete按钮可以销毁表行代表的记录。
当用户点击“ 删除”按钮时,我会显示一条警报,允许用户确认或取消删除操作。
用户确认记录删除后,EventDetailController由于它不再相关,因此我想将其删除,因为它代表已删除的记录。
点击“ 删除”按钮时,将调用以下IBAction定义:EventDetailController
@IBAction func deleteButtonTapped(_ sender: WKInterfaceButton) {
let deleteAction = WKAlertAction(title: "Delete", style: .destructive) {
// delete the record
// as long as the delete was successful, dismiss the detail view
self.dismiss()
}
let cancelAction = WKAlertAction(title: "Cancel", …Run Code Online (Sandbox Code Playgroud) watchkit ×7
apple-watch ×4
swift ×4
watchos ×4
ios ×3
watchos-2 ×2
beta ×1
ios8.2 ×1
storyboard ×1
titlebar ×1
watchos-10 ×1
xcode ×1