Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/106.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UIButton';s标题标签不可访问,具体取决于上下文_Ios - Fatal编程技术网

Ios UIButton';s标题标签不可访问,具体取决于上下文

Ios UIButton';s标题标签不可访问,具体取决于上下文,ios,Ios,在我的一门课上,我可以跑步 UIButton *testButton = [UIButton buttonWithType:UIButtonTypeCustom]; NSLog(@"testButton's titleLabel is %@", testButton.titleLabel); 它可以很好地打印标题标签: 2013-02-26 19:11:49.223 Facebook[82876:c07] testButton's titleLabel is <UIButtonLabel

在我的一门课上,我可以跑步

UIButton *testButton = [UIButton buttonWithType:UIButtonTypeCustom];
NSLog(@"testButton's titleLabel is %@", testButton.titleLabel);
它可以很好地打印标题标签:

2013-02-26 19:11:49.223 Facebook[82876:c07] testButton's titleLabel is <UIButtonLabel: 0x1aad39f0; frame = (0 0; 0 0); clipsToBounds = YES; hidden = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x1aad3a90>>
2013-02-26 19:11:49.223 Facebook[82876:c07]testButton的标题标签是
然而,在测试期间的类中,当我尝试访问testButton的标题标签时,即使我使用的是相同的两行代码,我也会得到
EXC\u BAD\u ACCESS


有什么想法吗?

如果您正在访问一个已发布的对象,请保留此对象直到您使用它,或者使用ARCIt。看起来它应该可以同时使用这两个对象。buttonWithType返回一个自动删除的UIButton,而titelLabel属性是
@property(非原子、只读、保留)UILabel*titleLabel
Rose
EXC_BAD_ACCESS
仅当该对象从内存中释放时才会出现。另外,您的
titleable
属性是正确的,但是
testButton
只是一个局部变量。。