【发布时间】:2013-02-16 11:36:06
【问题描述】:
我在XIB 文件中设计了一个UIView。基本上带有一个导航栏和一个按钮来关闭UIVIew。我想在整个应用程序的几个UIViewControllers 中显示这个UIView。
下面是我到目前为止所使用的代码。但是UIView 没有显示出来。
我的ViewControllers 是在storyboard 中设计的,但是我需要一个简单的 UIView,这就是为什么我创建了一个新的 UIView 自定义子类以及一个同名的 xib 文件。文件的所有者也设置为自定义子类。这里还需要什么?
@interface BottomSlidingView : UIView //this is my UIView
{
}
@implementation BottomSlidingView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self setUserInteractionEnabled:YES];
NSLog(@"Bottom View Loaded"); //I get this log entry but the view doesn't showup.
}
return self;
}
- (BOOL)loadMyNibFile {
if (![[NSBundle mainBundle] loadNibNamed:@"BottomSlidingView" owner:self options:nil]) {
return NO;
}
return YES;
}
这就是我在UIViewController 中调用自定义UIView 的方式。
-(void)shareButton:(UIBarButtonItem *)button
{
NSLog(@"share button clicked");
BottomSlidingView *bsv = [[BottomSlidingView alloc] initWithFrame:CGRectMake(20, 480, 280, 420)];
[bsv loadMyNibFile];
[self.view insertSubview:bsv belowSubview:self.optionsToolBar]; //this toolbar is a subview that I am adding to this view controller.
}
【问题讨论】:
标签: iphone ios uiview uiviewcontroller