【已解决】UILabel 怎么从.json文件里取出来?

从.json文件里取不出UILabel 用示例里取UILabel的方法取不出,怎么办啊?

检查下tag是否正确:2:

请贴出代码,版主会帮你解决的:7:

UILabel * friend_num = static_cast<UILabel *>(pNode->getWidgetByName(“LabelBMFont_1192”));

friend_num 没取出来.

LabelBMFont_1192在编辑器里就是这么设置的么?如果是的话,麻烦将这个项目导出文件发给我试下。

怎么传给你啊?

{
“classname”: null,
“name”: null,
“animation”: {
“classname”: null,
“name”: “AnimationManager”,
“actionlist”: ]
},
“dataScale”: 1,
“designHeight”: 960,
“designWidth”: 640,
“textures”: ],
“version”: “1.2.0.0”,
“widgetTree”: {
“classname”: “Panel”,
“name”: null,
“children”:
{
“classname”: “ImageView”,
“name”: null,
“children”:
{
“classname”: “Button”,
“name”: null,
“children”: ],
“options”: {
“__type”: “ComGUIButtonSurrogate:#EditorCommon.JsonModel.Component.GUI”,
“classname”: “Button”,
“name”: “Button_524_0_0”,
“ZOrder”: 0,
“actiontag”: 1186,
“anchorPointX”: 0.5,
“anchorPointY”: 0.5,
“classType”: null,
“colorB”: 255,
“colorG”: 255,
“colorR”: 255,
“flipX”: false,
“flipY”: false,
“height”: 74,
“ignoreSize”: true,
“layoutParameter”: null,
“opacity”: 255,
“positionPercentX”: -0.381861567,
“positionPercentY”: 0.0113636367,
“positionType”: 0,
“rotation”: 0,
“scaleX”: 1,
“scaleY”: 1,
“sizePercentX”: 0.245823383,
“sizePercentY”: 0.454545468,
“sizeType”: 0,
“tag”: 89,
“touchAble”: true,
“useMergedTexture”: false,
“visible”: true,
“width”: 96,
“x”: -160,
“y”: 1,
“capInsetsHeight”: 0,
“capInsetsWidth”: 0,
“capInsetsX”: 0,
“capInsetsY”: 0,
“disabled”: null,
“disabledData”: {
“path”: “Resources/common/return_button_a.png”,
“plistFile”: null,
“resourceType”: 0
},
“fontName”: “微软雅黑”,
“fontSize”: 14,
“fontType”: 0,
“normal”: null,
“normalData”: {
“path”: “Resources/common/return_button.png”,
“plistFile”: null,
“resourceType”: 0
},
“pressed”: null,
“pressedData”: {
“path”: “Resources/common/return_button_a.png”,
“plistFile”: null,
“resourceType”: 0
},
“scale9Enable”: false,
“scale9Height”: 74,
“scale9Width”: 96,
“text”: “”,
“textColorB”: 255,
“textColorG”: 255,
“textColorR”: 255
}
},
{
“classname”: “ImageView”,
“name”: null,
“children”: ],
“options”: {
“__type”: “ComGUIImageViewSurrogate:#EditorCommon.JsonModel.Component.GUI”,
“classname”: “ImageView”,
“name”: “ImageView_525_0_0”,
“ZOrder”: 1,
“actiontag”: 1187,
“anchorPointX”: 0.5,
“anchorPointY”: 0.5,
“classType”: null,
“colorB”: 255,
“colorG”: 255,
“colorR”: 255,
“flipX”: false,
“flipY”: false,
“height”: 50,
“ignoreSize”: true,
“layoutParameter”: null,
“opacity”: 255,
“positionPercentX”: 0.06443914,
“positionPercentY”: 0,
“positionType”: 0,
“rotation”: 0,
“scaleX”: 1,
“scaleY”: 1,
“sizePercentX”: 0.190930784,
“sizePercentY”: 0.909090936,
“sizeType”: 0,
“tag”: 90,
“touchAble”: false,
“useMergedTexture”: false,
“visible”: true,
“width”: 162,
“x”: 27,
“y”: 0,
“capInsetsHeight”: 0,
“capInsetsWidth”: 0,
“capInsetsX”: 0,
“capInsetsY”: 0,
“fileName”: null,
“fileNameData”: {
“path”: “Resources/friends/list_word.png”,
“plistFile”: null,
“resourceType”: 0
},
“scale9Enable”: false,
“scale9Height”: 50,
“scale9Width”: 162
}
}
],
“options”: {
“__type”: “ComGUIImageViewSurrogate:#EditorCommon.JsonModel.Component.GUI”,
“classname”: “ImageView”,
“name”: “ImageView_523_0_0”,
“ZOrder”: 1,
“actiontag”: 1185,
“anchorPointX”: 0.5,
“anchorPointY”: 0.5,
“classType”: null,
“colorB”: 255,
“colorG”: 255,
“colorR”: 255,
“flipX”: false,
“flipY”: false,
“height”: 88,
“ignoreSize”: true,
“layoutParameter”: null,
“opacity”: 255,
“positionPercentX”: 0.321875,
“positionPercentY”: 0.775,
“positionType”: 0,
“rotation”: 0,
“scaleX”: 1,
“scaleY”: 1,
“sizePercentX”: 0.125,
“sizePercentY”: 0.0833333358,
“sizeType”: 0,
“tag”: 88,
“touchAble”: false,
“useMergedTexture”: false,
“visible”: true,
“width”: 419,
“x”: 206,
“y”: 744,
“capInsetsHeight”: 0,
“capInsetsWidth”: 0,
“capInsetsX”: 0,
“capInsetsY”: 0,
“fileName”: null,
“fileNameData”: {
“path”: “Resources/common/label.png”,
“plistFile”: null,
“resourceType”: 0
},
“scale9Enable”: false,
“scale9Height”: 88,
“scale9Width”: 419
}
},
{
“classname”: “ImageView”,
“name”: null,
“children”: ],
“options”: {
“__type”: “ComGUIImageViewSurrogate:#EditorCommon.JsonModel.Component.GUI”,
“classname”: “ImageView”,
“name”: “ImageView_1188”,
“ZOrder”: 1,
“actiontag”: 1188,
“anchorPointX”: 0.5,
“anchorPointY”: 0.5,
“classType”: null,
“colorB”: 255,
“colorG”: 255,
“colorR”: 255,
“flipX”: false,
“flipY”: false,
“height”: 41,
“ignoreSize”: true,
“layoutParameter”: null,
“opacity”: 255,
“positionPercentX”: 0.9,
“positionPercentY”: 0.797916651,
“positionType”: 0,
“rotation”: 0,
“scaleX”: 1,
“scaleY”: 1,
“sizePercentX”: 0.125,
“sizePercentY”: 0.0833333358,
“sizeType”: 0,
“tag”: 185,
“touchAble”: false,
“useMergedTexture”: false,
“visible”: true,
“width”: 87,
“x”: 576,
“y”: 766,
“capInsetsHeight”: 0,
“capInsetsWidth”: 0,
“capInsetsX”: 0,
“capInsetsY”: 0,
“fileName”: null,
“fileNameData”: {
“path”: “Resources/friends/plate_friend.png”,
“plistFile”: null,
“resourceType”: 0
},
“scale9Enable”: false,
“scale9Height”: 41,
“scale9Width”: 87
}
},
{
“classname”: “ListView”,
“name”: null,
“children”: ],
“options”: {
“__type”: “ComGUIListViewSurrogate:#EditorCommon.JsonModel.Component.GUI”,
“classname”: “ListView”,
“name”: “ListView_1189”,
“ZOrder”: 3,
“actiontag”: 1189,
“anchorPointX”: 0,
“anchorPointY”: 0,
“classType”: null,
“colorB”: 255,
“colorG”: 255,
“colorR”: 255,
“flipX”: false,
“flipY”: false,
“height”: 700,
“ignoreSize”: false,
“layoutParameter”: null,
“opacity”: 255,
“positionPercentX”: 0,
“positionPercentY”: 0.154166669,
“positionType”: 0,
“rotation”: 0,
“scaleX”: 1,
“scaleY”: 1,
“sizePercentX”: 1,
“sizePercentY”: 0.7291667,
“sizeType”: 0,
“tag”: 186,
“touchAble”: true,
“useMergedTexture”: false,
“visible”: true,
“width”: 640,
“x”: 0,
“y”: 148,
“backGroundImage”: null,
“backGroundImageData”: null,
“backGroundScale9Enable”: false,
“bgColorB”: 255,
“bgColorG”: 150,
“bgColorOpacity”: 100,
“bgColorR”: 150,
“bgEndColorB”: 255,
“bgEndColorG”: 150,
“bgEndColorR”: 150,
“bgStartColorB”: 255,
“bgStartColorG”: 255,
“bgStartColorR”: 255,
“bounceEnable”: true,
“capInsetsHeight”: 0,
“capInsetsWidth”: 0,
“capInsetsX”: 0,
“capInsetsY”: 0,
“clipAble”: false,
“colorType”: 0,
“direction”: 1,
“gravity”: 0,
“innerHeight”: 700,
“innerWidth”: 640,
“itemMargin”: 0,
“vectorX”: 0,
“vectorY”: -0.5
}
},
{
“classname”: “LabelBMFont”,
“name”: null,
“children”: ],
“options”: {
“__type”: “ComGUILabelBMFontSurrogate:#EditorCommon.JsonModel.Component.GUI”,
“classname”: “LabelBMFont”,
“name”: “LabelBMFont_1192”,
“ZOrder”: 2,
“actiontag”: 1192,
“anchorPointX”: 0.5,
“anchorPointY”: 0.5,
“classType”: null,
“colorB”: 255,
“colorG”: 255,
“colorR”: 255,
“flipX”: false,
“flipY”: false,
“height”: 37,
“ignoreSize”: true,
“layoutParameter”: null,
“opacity”: 255,
“positionPercentX”: 0.8421875,
“positionPercentY”: 0.7496597,
“positionType”: 0,
“rotation”: 0,
“scaleX”: 1,
“scaleY”: 1,
“sizePercentX”: 0.3671875,
“sizePercentY”: 0.0385416672,
“sizeType”: 0,
“tag”: 189,
“touchAble”: false,
“useMergedTexture”: false,
“visible”: true,
“width”: 29,
“x”: 539,
“y”: 719,
“fileNameData”: {
“path”: “GUI/missing-font.fnt”,
“plistFile”: null,
“resourceType”: 0
},
“text”: “1”
}
},
{
“classname”: “LabelBMFont”,
“name”: null,
“children”: ],
“options”: {
“__type”: “ComGUILabelBMFontSurrogate:#EditorCommon.JsonModel.Component.GUI”,
“classname”: “LabelBMFont”,
“name”: “LabelBMFont_1193”,
“ZOrder”: 2,
“actiontag”: 1193,
“anchorPointX”: 0.5,
“anchorPointY”: 0.5,
“classType”: null,
“colorB”: 255,
“colorG”: 255,
“colorR”: 255,
“flipX”: false,
“flipY”: false,
“height”: 37,
“ignoreSize”: true,
“layoutParameter”: null,
“opacity”: 255,
“positionPercentX”: 0.921875,
“positionPercentY”: 0.748958349,
“positionType”: 0,
“rotation”: 0,
“scaleX”: 1,
“scaleY”: 1,
“sizePercentX”: 0.3671875,
“sizePercentY”: 0.0385416672,
“sizeType”: 0,
“tag”: 190,
“touchAble”: false,
“useMergedTexture”: false,
“visible”: true,
“width”: 72,
“x”: 590,
“y”: 719,
“fileNameData”: {
“path”: “GUI/missing-font.fnt”,
“plistFile”: null,
“resourceType”: 0
},
“text”: “/30”
}
}
],
“options”: {
“__type”: “ComGUIPanelSurrogate:#EditorCommon.JsonModel.Component.GUI”,
“classname”: “Panel”,
“name”: “Panel_1183”,
“ZOrder”: 0,
“actiontag”: -1,
“anchorPointX”: 0,
“anchorPointY”: 0,
“classType”: null,
“colorB”: 255,
“colorG”: 255,
“colorR”: 255,
“flipX”: false,
“flipY”: false,
“height”: 960,
“ignoreSize”: false,
“layoutParameter”: null,
“opacity”: 255,
“positionPercentX”: 0,
“positionPercentY”: 0,
“positionType”: 0,
“rotation”: 0,
“scaleX”: 1,
“scaleY”: 1,
“sizePercentX”: 1,
“sizePercentY”: 1,
“sizeType”: 0,
“tag”: 181,
“touchAble”: false,
“useMergedTexture”: false,
“visible”: true,
“width”: 640,
“x”: 0,
“y”: 0,
“backGroundImage”: null,
“backGroundImageData”: null,
“backGroundScale9Enable”: false,
“bgColorB”: 255,
“bgColorG”: 200,
“bgColorOpacity”: 0,
“bgColorR”: 150,
“bgEndColorB”: 255,
“bgEndColorG”: 200,
“bgEndColorR”: 150,
“bgStartColorB”: 255,
“bgStartColorG”: 255,
“bgStartColorR”: 255,
“capInsetsHeight”: 0,
“capInsetsWidth”: 0,
“capInsetsX”: 0,
“capInsetsY”: 0,
“clipAble”: false,
“colorType”: 1,
“layoutType”: 0,
“vectorX”: 0,
“vectorY”: -0.5
}
}
}

是不是改了了Text,还是获取的层级是不是对的?

UILabelBMFont * friend_num = static_cast<UILabelBMFont *>(pNode->getWidgetByName(“LabelBMFont_1192”));

如果UI里的tag 比较乱 建议你先用name来获取。
单个画布里控件的 tag 不是唯一的。
出现一样的话就会出问题。。。

他用的是name哦~~只不过类型转换错了