优化组件初始化函数
authorCaisking <3449750381@qq.com>
Fri, 9 Aug 2024 10:01:22 +0000 (18:01 +0800)
committerCaisking <3449750381@qq.com>
Fri, 9 Aug 2024 10:01:22 +0000 (18:01 +0800)
code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.cpp

index 5342926..bc3df8d 100644 (file)
@@ -170,11 +170,14 @@ namespace OHOS
     bool InitButtonExt(UILabelButtonExt *&button, int left, int top, int width, int height, const char *viewId, UIResourceTextId id, int fontSize)
     {
         // 创建新按钮(如果当前按钮为空)
-        button = new UILabelButtonExt();
         if (button == nullptr)
         {
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitButtonExt is error");
-            return false; // 内存分配失败,返回false
+            button = new UILabelButtonExt();
+            if (button == nullptr)
+            {
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitButtonExt is error");
+                return false; // 内存分配失败,返回false
+            }
         }
         button->SetPosition(left, top);
         button->Resize(width, height);