如何使 UIWebView 在 Objective-C 中不可见
我必须隐藏 UIView 的 UIWebView onload,并仅在单击 UIButton 时显示它...我尝试这样做:
在 .hi 中创建与 xib 对应的 IBOutlet。
#import <UIKit/UIKit.h>
@interface SingleViewController : UIViewController{
UIWebView *gif;
UIButton *go;
}
@property(nonatomic,retain) IBOutlet UIWebView *gif;
@property(nonatomic,retain) IBOutlet UIButton *go;
@end
在 .mi 中尝试以这种方式隐藏 uiwebview:
@implementation SingleViewController
@synthesize sug;
@synthesize gif;
@synthesize avvia;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
gif.hidden=YES;
UIImage *keys = [UIImage imageNamed:@"chiave.png"];
[self.go setImage:chiave forState:UIControlStateNormal];
[self.go setImage:chiave forState:UIControlStateHighlighted];
[self.go setImage:chiave forState:UIControlStateDisabled];
[self.go setImage:chiave forState:UIControlStateSelected];
}
return self;
}
我以这种方式加载此 uiview:
SingleViewController *single = [[SingleViewController alloc]initWithNibName:@"SingleViewController" bundle:nil];
[self.view addSubview:single.view];
出了什么问题?
I have to hide an UIWebView onload of an UIView, and show it only when an UIButton is clicked... i try this:
In .h i create the IBOutlet corresponding to xib.
#import <UIKit/UIKit.h>
@interface SingleViewController : UIViewController{
UIWebView *gif;
UIButton *go;
}
@property(nonatomic,retain) IBOutlet UIWebView *gif;
@property(nonatomic,retain) IBOutlet UIButton *go;
@end
in .m i try to hide uiwebview in this way:
@implementation SingleViewController
@synthesize sug;
@synthesize gif;
@synthesize avvia;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
gif.hidden=YES;
UIImage *keys = [UIImage imageNamed:@"chiave.png"];
[self.go setImage:chiave forState:UIControlStateNormal];
[self.go setImage:chiave forState:UIControlStateHighlighted];
[self.go setImage:chiave forState:UIControlStateDisabled];
[self.go setImage:chiave forState:UIControlStateSelected];
}
return self;
}
and i load this uiview in this way:
SingleViewController *single = [[SingleViewController alloc]initWithNibName:@"SingleViewController" bundle:nil];
[self.view addSubview:single.view];
What goes wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要等到调用
viewDidLoad:
才能隐藏 UIWebView。这是因为 nib 中的项目尚未实例化,并且对 nil 对象调用方法将不起作用。You need to wait until
viewDidLoad:
is called to hide the UIWebView. This is because the items in your nib have not been instantiated yet and calling methods on a nil object will have no effect.一些建议:
确保 initWithNibName:bundle: 实际上被调用,因为如果直接从 nib 文件加载视图控制器,则可能不会被调用。
添加子视图时,请确保也设置它的框架。
A couple of suggestions:
Make sure that initWithNibName:bundle: is actually being called, since it may not be if the View Controller is loaded from a nib file directly.
When adding your subview, make sure to set it's frame, too.