我的主界面中有一个按钮。我从故事板中的按钮向ctl + drag
做了InterfaceController.m
,然后在结果方法中添加了NSLog
。这就是代码的样子
#import "InterfaceController.h"
@interface InterfaceController()
@end
@implementation InterfaceController
- (void)awakeWithContext:(id)context {
[super awakeWithContext:context];
NSLog(@"awakeWithContext!");
// Configure interface objects here.
}
- (IBAction)Alarm {
NSLog(@"Alarm!");
}
- (void)willActivate {
// This method is called when watch view controller is about to be visible to user
[super willActivate];
NSLog(@"willActivate!");
}
- (void)didDeactivate {
// This method is called when watch view controller is no longer visible
[super didDeactivate];
NSLog(@"didDeactivate!");
}
@end
我还拍了一张显示日志的屏幕截图。当我按下模拟器中的“警报”按钮时,没有记录。
更新
我只是按照此视频中的示例进行操作。 “如何使用Xcode将WKInterfaceButton连接到代码中的操作”https://www.youtube.com/watch?v=CuCuL-a608w
我将其添加到标题- (IBAction)alarmPressed:(id)sender;
我把它放在视图控制器
- (IBAction)alarmPressed:(id)sender
{
NSLog(@"alarmPressed!");
}
我将已发送的操作选择拖动到Interface Controller
并选中alarmPressed
。按下时仍然不会产生日志。特征还包括“启用用户交互”