怎样点击按钮打开一个xib创建的界面 本帖最后由 zzxap 于 2011-06-24 14:34:04 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 xxxx.xib的视图名叫什么?怎样初始化这个视图 刚学吗?那好,请你抛开IB好了⋯⋯我有N个理由让你用代码而不是用IB来构建你的工程。 那个VIEW的CONTROLLER来定义一个对象,加载就OK了 我新建了一个class和xib想从另一个视图点击一个按钮打开这个xib的视图不知道我描述的清楚不 具体代码?nextView *nextv = [[nextView alloc]init];[self.navigationController pushViewController:nextv animated:YES];提示 request for member 'navigationController' in something not a structure or union什么原因? 在ObjC中,UIview与UIViewController 是不同的你完全可以在一个UIViewController写两个UIView,然后点击按钮时来回切换。如果不明白,我发例子出来 建议以后经常上http://stackoverflow.com/而不是csdn这里是聊天的地方 一般的xib文件创建的是UIViewController还是uiview? #import "SwitchViewCtl.h"@implementation SwitchViewCtl-(id)init{ if (self=[super init]) { v1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 400, 400)]; v2 = [[UIView alloc] initWithFrame:CGRectMake(0, 500, 400, 600)]; //先初始化两个View [v1 setBackgroundColor:[UIColor cyanColor]]; UIButton *bt = [[UIButton alloc] initWithFrame:CGRectMake(100, 250, 100, 50)]; [bt setImage:[UIImage imageNamed:@"114.png"] forState:UIControlStateNormal]; bt.titleLabel.text = @"显 示"; [bt addTarget:self action:@selector(openView) forControlEvents:UIControlEventTouchDown]; [v1 addSubview:bt]; [self.view addSubview:v1];//加载一个 } return self;}-(void)openView{ v1.hidden=YES;//可以先隐藏之,也可以设置Frame覆盖掉,当然还可以,从主ViewCtl中删除 [v1 removeFromSuperview]; [v2 setBackgroundColor:[UIColor blueColor]]; [self.view addSubview:v2];//加载另一个 [self.view setNeedsDisplay];//这里是刷新啦}- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; SwitchViewCtl *switchViewCtl = [[SwitchViewCtl alloc] init]; [window addSubview:switchViewCtl.view]; [self.window makeKeyAndVisible]; return YES;}int main(int argc, char *argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; int retVal = UIApplicationMain(argc, argv, nil, @"ViewSwitchAppDelegate"); [pool release]; return retVal;}这样能说清楚吗?还是把工程文件发给你比较好 XCode版本和SDK版本 如何修改已经注册好的UILocalNotification IPHONE 图形开发 委托到底是什么? zip压缩+base64加密 发布问题再问,继续吐血中!!!! iOS7.1 4s莫名的崩溃日志 不是一定发生 【求助】iOS Sqlite3 使用Update 无法更新数据库 跪求解决crash!!!在线等, 急! ios与android如何通过WIFI进行文件传输 关于修改mac os x版本号的问题 UITabBarController只能用在mainwindows.xib里面吗?
那好,请你抛开IB好了⋯⋯
我有N个理由让你用代码而不是用IB来构建你的工程。
[self.navigationController pushViewController:nextv animated:YES];提示 request for member 'navigationController' in something not a structure or union什么原因?
你完全可以在一个UIViewController写两个UIView,然后点击按钮时来回切换。
如果不明白,我发例子出来
http://stackoverflow.com/
而不是csdn
这里是聊天的地方
#import "SwitchViewCtl.h"
@implementation SwitchViewCtl-(id)init{
if (self=[super init]) {
v1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 400, 400)];
v2 = [[UIView alloc] initWithFrame:CGRectMake(0, 500, 400, 600)];
//先初始化两个View
[v1 setBackgroundColor:[UIColor cyanColor]];
UIButton *bt = [[UIButton alloc] initWithFrame:CGRectMake(100, 250, 100, 50)];
[bt setImage:[UIImage imageNamed:@"114.png"] forState:UIControlStateNormal];
bt.titleLabel.text = @"显 示";
[bt addTarget:self action:@selector(openView) forControlEvents:UIControlEventTouchDown];
[v1 addSubview:bt];
[self.view addSubview:v1];//加载一个
}
return self;
}
-(void)openView{
v1.hidden=YES;//可以先隐藏之,也可以设置Frame覆盖掉,当然还可以,从主ViewCtl中删除 [v1 removeFromSuperview];
[v2 setBackgroundColor:[UIColor blueColor]];
[self.view addSubview:v2];//加载另一个
[self.view setNeedsDisplay];//这里是刷新啦
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
SwitchViewCtl *switchViewCtl = [[SwitchViewCtl alloc] init];
[window addSubview:switchViewCtl.view];
[self.window makeKeyAndVisible];
return YES;
}int main(int argc, char *argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, @"ViewSwitchAppDelegate");
[pool release];
return retVal;
}这样能说清楚吗?还是把工程文件发给你比较好