我是新手,我想得到一些建议,因为我不知道我做错了什么。我想在 xcode 中制作一个应用程序,带有一个带有一些项目的UIView
,当您做某事时,第一个UIView
上方会弹出另一个UIView
(比第一个小)。弹出窗口UIView
将是一个自定义类。
我从UIViewController
模板和初始UIView
开始,并且我已经链接了.storyboard
中的所有项目,并且可以工作。但是当我创建自己的UIView
类(from objective-C class)
,将第二个UIView
放在storyboard
中的第一个并将其链接到我的类时,出了点问题。
UIView
出现,但当我尝试将其设置为隐藏时,它没有回答。就像它没有收到消息一样,所以我认为我没有以编程方式很好地链接它,只是因为storyboard
而出现.
我不知道我是否必须创建另一个UIView控制器而不是UIView,或者这是否是正确的路径。
谁能解释一下我,或者只是用第二个视图的实例化编写一点代码片段并添加它?
非常感谢!!
(我粘贴了一些代码,声明在 .h 中,实例化在 .m 中)
#import <UIKit/UIKit.h>
#import "EditView.h"
@interface ReleaseViewController : UIViewController <UIWebViewDelegate, UISearchBarDelegate> {
IBOutlet UIWebView *web;
IBOutlet UISearchBar *search;
IBOutlet EditView *evHack;
}
@property (nonatomic, retain) IBOutlet UIWebView *web;
@property (nonatomic, retain) IBOutlet UISearchBar *search;
@property (nonatomic, retain) IBOutlet EditView *evHack;
@end
- (void)viewDidLoad
{
[super viewDidLoad];
search.delegate = self;
web.delegate = self;
evHack = [evHack initWithFrame:CGRectMake(0, 44, 320, 377)];
[evHack setHidden:YES];
}
编辑视图类(我仍然一无所有):
#import <UIKit/UIKit.h>
@interface EditView : UIView
@end
#import "EditView.h"
@implementation EditView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
NSLog(@"View created");
}
return self;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
// Drawing code
}
*/
@end
initWithFrame 仅在分配/初始化应用程序时才有效。如果它已经初始化,在这种情况下由故事板初始化,只需设置它的框架:
evHack.frame = CGRectMake(0,44, 320, 377);
我不知道它在 IB 中是什么样子的,但是如果你也在 IB 中设置它,在代码中设置它的框架可能是多余的。要检查 evHack 是否正确连接,NSLog evHack in viewDidLoad。如果你找回nil
,它就没有正确连接。