分配窗口.load和.unload函数时出错

时间:2014-06-10 21:31:28

标签: c pebble-watch pebble-sdk

我正在处理一个多窗口应用程序,在我的第二个窗口,我称之为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");
}

1 个答案:

答案 0 :(得分:2)

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

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

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