1 / 11

Exploring the GUI

Exploring the GUI. What if we want to add a UIView (for example a UILabel) at run time inside the navigation bar? We need to access that view, create a label, and add it as a subview How do we find that view?. Exploring the GUI. From a UIView named myView, we can go up

wilda
Télécharger la présentation

Exploring the GUI

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Exploring the GUI • What if we want to add a UIView (for example a UILabel) at run time inside the navigation bar? • We need to access that view, create a label, and add it as a subview • How do we find that view?

  2. Exploring the GUI • From a UIView named myView, we can go up • myView.superview (a UIView) • or down • myView.subviews (a NSArray of UIViews)

  3. Exploring the GUI • From a UIViewController named myVC, we can go up • myVC.parentViewController (a UIViewController) • or down • myVC.childViewControllers (a NSArray of UIViewControllers)

  4. Exploring the GUI • Inside the DetailViewController, get the parent view controller, look at its view, and the children of its view • UIViewController *parentC = self.parentViewController; • UIView *topView = parentC.view; • NSArray *views = topView.subviews;

  5. Exploring the GUI • Use NSLog to output the views: there are 2 of them • iPad dimensions are: • UINavigationTransitionView: 0, 0, 703, 768 • UINavigationBar: 0, 20, 703, 44 •  navigation bar is on top and its height is 44 pixels

  6. Exploring the GUI • Get the navigation bar view • UINavigationBar *bar = (UINavigationBar *) [views objectAtIndex: 1]; • Now place a label inside it

  7. Exploring the GUI • Run the app, back and forth • The label stays when we go back • Inside the viewWillAppear method of MasterViewController, we can remove it

  8. Exploring the GUI • If we have a method named removeLabel in the DetailViewController class, we could call it from viewWillAppear inside the MasterViewController class • [self.detailViewController removeLabel];

  9. Exploring the GUI • Inside removeLabel, we could search for the label, based on some characteristics (class name, color, text, ..) • Better, we can tag it when we add it • UIView has a property named tag (NSInteger) • label.tag = 99;

  10. Exploring the GUI • From a parent view, we can use the method viewWithTag (searches current view and subviews) to retrieve the label • UILabel *label = [someParentView viewWithTag: 99]; • Now remove it • [label removeFromSuperview];

  11. Exploring the GUI • We could also declare the UILabel as an instance variable, create it when the view loads, and then set it visible or invisible using the hidden property • label.hidden = YES; • label.hidden = NO;

More Related