我正在尝试实现一个按钮操作,当按下 Select 按钮时在我的 ScrollLayer 上显示文本。我用了:
scroll_layer_set_click_config_onto_window(scrollLayer, window);
自动设置 BUTTON_UP 和 BUTTON_DOWN 回调函数(滚动)。那么我想设置一个 BUTTON_SELECT 回调函数。我写了这两个函数:
//Performs an action whenver the 'select' button is pressed
void select_click_handler(ClickRecognizerRef recognizer, void *ctx) {
text_layer_set_text(textLayer, "You pressed select");
}
//Links the select button to a function, select_click_handler
void click_config_provider(void *ctx) {
window_single_click_subscribe(BUTTON_ID_SELECT, select_click_handler);
}
在我的初始化程序中,我有:
void init() {
window = window_create();
window_set_window_handlers(window, (WindowHandlers) {
.load = window_load,
.unload = window_unload,
});
window_set_click_config_provider(window, click_config_provider);
window_stack_push(window,true);
}
当我运行它时,它编译并安装在手表上就好了,但是,当我点击选择按钮时,什么也没有发生。当我注释掉scroll_layer_set_click_config_onto_window(scrollLayer, window);
它时,它就像它应该的那样工作。
有没有办法覆盖选择按钮回调而不必注释掉上面的行?
提前致谢!