【发布时间】:2016-02-15 08:57:17
【问题描述】:
您好,我是 ios 新手,在我的应用中,我正在使用 .xib 文件加载 UIView
当我单击第一个按钮时,我想加载 FirstView 并删除其他视图 当我单击第二个按钮时,我想加载 SecondView 并删除其他视图 当我单击第三个按钮时,我想加载 ThirdView 并删除 otherviews
我的代码:-
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize leftView,rightView;
- (void)viewDidLoad {
[super viewDidLoad];
}
- (IBAction)FirstAction:(id)sender {
FirstView * test1 = [[FirstView alloc]initWithFrame:CGRectMake(0, 0, rightView.frame.size.width, rightView.frame.size.height)];
test1.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
[rightView addSubview:test1];
}
- (IBAction)SecondAction:(id)sender {
SecondView * test2 = [[SecondView alloc]initWithFrame:CGRectMake(0, 0, rightView.frame.size.width, rightView.frame.size.height)];
test2.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
[rightView addSubview:test2];
}
- (IBAction)ThirdAction:(id)sender {
ThirdView * test3 = [[ThirdView alloc]initWithFrame:CGRectMake(0, 0, rightView.frame.size.width, rightView.frame.size.height)];
test3.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
[rightView addSubview:test3];
}
@end
【问题讨论】:
-
试试我提供的解决方案
-
您说您正在使用 xib 文件加载视图。但是您正在您的操作方法中以编程方式创建它们。你的项目中有 xib 文件吗?
-
是的,我的项目中有 xib 文件,这是我的示例应用程序
标签: ios objective-c xib