gpt4 book ai didi

c - 分配窗口 .load 和 .unload 函数时出现错误

转载 作者:太空宇宙 更新时间:2023-11-04 08:39:54 24 4
gpt4 key购买 nike

我正在开发一个多窗口应用程序,在我的第二个窗口上,我调用这个 init() 函数

static struct MessageUI {
Window *window;
MenuLayer *menu_layer;
} ui;

...
...
...

void messages_init(void) {
ui.window = window_create();

window_set_window_handlers(ui.window, (WindowHandlers) {
.load = window_load,
.unload = window_unload
});
}

当我运行代码时,我收到与 .load 和 .unload 赋值运算符有关的错误。

../src/messages.c: In function 'messages_init':
../src/messages.c:63:3: error: initialization from incompatible pointer type [-Werror]
../src/messages.c:63:3: error: (near initialization for 'handlers.load') [-Werror]
../src/messages.c:65:2: error: initialization from incompatible pointer type [-Werror]
../src/messages.c:65:2: error: (near initialization for 'handlers.unload') [-Werror]

知道为什么会出现这个错误吗?

编辑

这是我的 window_load 和 window_unload 函数

static void window_load(void) {
// Create it - 12 is approx height of the top bar
ui.menu_layer = menu_layer_create(GRect(0,0,144,168-16));
menu_layer_set_click_config_onto_window(ui.menu_layer,ui.window);

MenuLayerCallbacks callbacks = {
.draw_row = (MenuLayerDrawRowCallback) draw_row_callback,
.get_num_rows = (MenuLayerGetNumberOfRowsInSectionsCallback) num_rows_callback,
.select_click = (MenuLayerSelectCallback) select_click_callback
};
menu_layer_set_callbacks(ui.menu_layer, NULL, callbacks);

//Add to window
layer_add_child(window_get_root_layer(ui.window), menu_layer_get_layer(ui.menu_layer));
}

static void window_unload(void) {
APP_LOG(APP_LOG_LEVEL_DEBUG, "unloading message UI");
}

最佳答案

发生该错误是因为 window_loadwindow_unload 都旨在接收指向 Window 的指针。你应该这样声明它们:

static void window_load(Window *window) {
// ...
}

static void window_unload(Window *window) {
// ...
}

关于c - 分配窗口 .load 和 .unload 函数时出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24151191/

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