Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

kimti

macrumors newbie
Original poster
Feb 22, 2011
10
0
i create two nib files, and when i show the first nib, it show me the first view,and i click a button, i want to the first view change to the second view, but the nib no need change:

Code:
UIViewController *c = [[UIViewcontroller alloc] init];
[c.view setFrame:f];
[self.view addSubview:c.view]
this is ok.

but follow:

in .h file

Code:
UIView *v
@property(nonatomic,retail) UIView *v;
in .m file

Code:
@synthesize v;

UIViewController *c = [[UIViewcontroller alloc] init];
[c.view setFrame:f];
[self setV:v.view];
[self.view addSubview:v];
this is no show the view;
what happen?
thank you.
 
Last edited by a moderator:
you are confusing yourself with ur code.
Should be more like this
Code:
DetailViewController *a = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
[self.view addSubview:a];
 
Code:
@synthesize v;

UIViewController *c = [[UIViewcontroller alloc] init];
[c.view setFrame:f];
[self setV:v.view];
[self.view addSubview:v];

First, the more descriptive your variables the better off you'll be. using just c and v is just asking to confuse yourself. Here c is an instance of UIViewController and v is an instance of UIView controller. When you call

Code:
v.view

You are trying to access the view method of a UIView which doesn't exist and I would expect your program to crash with an exception about UIView not responding to message view.

So lets say you changed your setV to this to get rid of the error.

Code:
[self setV:v];

Now you are setting your member variable "v" to itself, so you don't get anything new. Probably what you want to do, is set your variable v to the view of your viewcontroller c.

Code:
[self setV:c.view];

I'm not so sure this is even what you want. Using a generic UIViewController doesn't seem to get you anything vs simply making a new UIView. I would do this instead...

Code:
UIView *newView = [[UIView alloc initWithFrame:f];
[self setV:newView];
[self.view addSubview:self.v];
[newView release];

Unless you really need the view controller in which case it would make more sense to hang onto a pointer to it, instead of it's view.

Code:
UIViewController *controller;
@property (nonatomic, retain) UIViewController *controller;

Code:
UIViewController *newController = [[UIViewController alloc] init];
[self setController:newController];
[newController release];
self.controller.view.frame = f;
[self.view addSubview:self.controller.view];
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.