0

I'm new here, don't be very hard on me :)

Learning iOS development and trying to display a small view to enter some data to my app, which is using storyboards.

I tried adding it as subview but I can't move it from the top-left corner or make the background to fade. Any advice on how to do this?

Forgot to mention that this is for iPhone.

Thanks

2
  • What have your tried (with code examples) and what errors or result did you get? Commented Jul 12, 2012 at 0:36
  • UIViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"addData"]; [self presentModalViewController:controller animated:YES]; tries this, it just presents the controller in full screen. and tried as [self.view addSubview:] Commented Jul 12, 2012 at 0:43

1 Answer 1

2

Based on your comment it seems that you don't have a clear understanding of the difference between UIView and UIViewController.

Think of a UIViewController as your screen. Your screen might be showing many different views at once, but they are all part of the UIViewController's view.

Rather then present a new UIViewController (i.e. screen), you want to do something like this:

//Use a XIB for this, not a storyboard UIView *newView = [[[NSBundle mainBundle] loadNibNamed:@"addData" owner:self options:nil] lastObject]; [self.view addSubview:newView]; 

I suggest reading these two guides from Apple until you understand the difference between a UIView and a UIViewController:

View Programming Guide

View Controller Programming Guide

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you! I tried this code and it worked UIView *controller = [[self.storyboard instantiateViewControllerWithIdentifier:@"addData"] view]; Is there a way I can do a flip animation and have another set of controls on the flip side? Also, can I darken the background/make it unaccessible till the user dismisses the subview?
Those should be asked as separate questions. Actually, search around and you'll find the answers.
Is it just me or -- judging from his comment -- the original author is looking to put a new viewcontroller atop his current view? Wouldn't the answer (as given, not in the comment) just add the view without using the view's separate controller?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.