本帖最后由 zzxap 于 2011-06-24 14:34:04 编辑

解决方案 »

  1.   

    xxxx.xib的视图名叫什么?怎样初始化这个视图
      

  2.   

    刚学吗?
    那好,请你抛开IB好了⋯⋯
    我有N个理由让你用代码而不是用IB来构建你的工程。
      

  3.   

    那个VIEW的CONTROLLER来定义一个对象,加载就OK了
      

  4.   

    我新建了一个class和xib想从另一个视图点击一个按钮打开这个xib的视图不知道我描述的清楚不
      

  5.   

    具体代码?nextView *nextv = [[nextView alloc]init];
    [self.navigationController pushViewController:nextv animated:YES];提示 request for member  'navigationController' in something not a structure or union什么原因?
      

  6.   

    在ObjC中,UIview与UIViewController 是不同的
    你完全可以在一个UIViewController写两个UIView,然后点击按钮时来回切换。
    如果不明白,我发例子出来
      

  7.   

    建议以后经常上
    http://stackoverflow.com/
    而不是csdn
    这里是聊天的地方
      

  8.   

    一般的xib文件创建的是UIViewController还是uiview?
      

  9.   


    #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;
    }这样能说清楚吗?还是把工程文件发给你比较好