Raplesyrup1
Raplesyrup1

Reputation: 83

OBJC View that replaces another view

I need to replace a view with another view (getting rid of the first view), but all I know are modal views. How do I do this?

Upvotes: 0

Views: 94

Answers (2)

zingle-dingle
zingle-dingle

Reputation: 1701

A couple different options..

One way is to add a view to your current view. This doesn't "get rid" of your orginal view but it does make it not visible if the new view is in front.

Code would look something like this.

newView = [[NewViewController alloc] initWithNibName:@"NewViewController" bundle:nil];
newView.view.frame = CGRectMake(x,y, newView.view.frame.size.width, newView.view.frame.size.height);
[newView SetMessage:@"my message"];  // set some data for the new view.
[self.view addSubview:newView.view ];  // show new view

Then the new view controller can close itself or just hide itself.

Upvotes: 1

Alex Wayne
Alex Wayne

Reputation: 187242

// In a controller method
[oldView removeFromSuperview];
[self.view addSubview:newView];

Upvotes: 3

Related Questions