添加了按钮、webview、添加了插座,但无法在代码中使用它们
我制作了一个工具栏,上面有两个按钮。然后我在类控制器中创建了两个出口。然后我将控制器连接到按钮并选择插座。
最后我重写了类文件(添加:
IBOutlet id next;
IBOutlet id previous;
到我的 .h 文件中)。
所以现在,一切看起来都很好。但后来我尝试在代码中的某处更改我的一个按钮的状态,如下所示:
next.enabled = YES;
我尝试使用 self.但不幸的是我收到此错误消息: 错误:请求在非结构或联合中“启用”成员
您知道那里发生了什么吗?
是的,我有:
#import <UIKit/UIKit.h>
:)
使用:
[next setEnabled:YES];
没有给我错误,但仍然不起作用...
最后,为了记录目的,这里是整个方法:
- (void)viewDidLoad {
[super viewDidLoad];
if (!self.currentLevel) {
self.currentLevel = @"1";
}
NSArray *etape = [self.etapes objectForKey:self.currentLevel];
if ([etape count] > 0) {
self.navigationItem.title = [etape objectAtIndex:1];
if ([etape count] > 1) {
[next setEnabled:YES];
}
} else {
self.navigationItem.title = @"Aucune étape";
}
}
当我这样做时:
NSLog(@"%@", [next class]);
它返回(null)...我想它应该是成为 UIBarButtonItem...
即使我在使用它们时没有收到任何错误,似乎也无法使用任何插座...
I made a toolbar with two buttons on it. I then created two outlets in my class controller. Then I hooked the the controller to the buttons and selected the outlets.
Finally I rewritten the class files (that added:
IBOutlet id next;
IBOutlet id previous;
to my .h file).
So now, everything looks okay. But then I try somewhere in the code to change the state of one of my button like this:
next.enabled = YES;
I tried with self. too but unfortunately I receive this error message:
error: request for member 'enabled' in something not a structure or union
Do you have any idea of what's happening there?
And yes I have:
#import <UIKit/UIKit.h>
:)
Using:
[next setEnabled:YES];
gives me no error but still doesn't work...
And finally, for documenting purposes here's the whole method:
- (void)viewDidLoad {
[super viewDidLoad];
if (!self.currentLevel) {
self.currentLevel = @"1";
}
NSArray *etape = [self.etapes objectForKey:self.currentLevel];
if ([etape count] > 0) {
self.navigationItem.title = [etape objectAtIndex:1];
if ([etape count] > 1) {
[next setEnabled:YES];
}
} else {
self.navigationItem.title = @"Aucune étape";
}
}
When I do:
NSLog(@"%@", [next class]);
It returns (null) ... I guess it is supposed to be UIBarButtonItem...
It seems that it is impossible to play with any outlets even if I don't receive any errors while playing with them...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
那应该是:
That should be:
我不确定 iphone SDK,因为我不使用它,但您可以使用以下方法启用/禁用工具栏项目。我通常使用按钮的标签来识别我的目标按钮。
I'm not sure about the iphone SDK because I don't use it, but you enable/disable toolbar items using the following method. I usually use the button's label to identify which button I target.