IOS Cocoa Programming in view Controller and view class (GO)

Source: Internet
Author: User

Category: IPhone2012-05-28 11:19 837 people read reviews (0) favorite reports Cocoa Programming Iosuinavigationcontrolleruiviewiphone

The iphone programming rules are: A window, multiple views .

UIView is the base class for many controls on the iphone screen. Each iphone user interface is built by a multitude of UIView and their specialized subclasses displayed in UIWindow (which is also a special UIView).

Display the view of the data:

    • Uitextview
    • UILabel
    • Uiimageview
    • UIWebView
    • Mkmapviews
    • Uiscrollview

selectable views (The following two view class instances are modal):

    • Uialertview
    • Uiactionsheet

all controls (controls are screen objects that convert user touches to callback triggers.) ):

    • UIButton
    • Uisegmentedcontrol
    • Uiswitch
    • UISlider
    • Uipagecontrol
    • Uitextfield

Table and Picker:

    • UITableView (table cell item with a UITableViewCell class for the row of the table)
    • Uipickerview

Various column styles:

    • Uinavigationbar (there is a navigation entry for the Uinavigationitem class for the navigation bar)
    • Uitabbar
    • Uisearchbar
    • Uitoolbar

In all iphone bar style views, only the Uitoolbar class can be used directly. The other three are done with the corresponding controller classes, rather than building and managing views directly.

Progress and activities:

    • Uiactivityindicatorview
    • Uiprogressview

Controller class
Uiviewcontroller class
Uiviewcontroller is responsible for creating the views it manages and removing them from memory when they are low in memory. It also responds to the standard system behavior. Syntactically speaking,Uiviewcontroller is the parent class of the view controller . The View controller class is an abstract class that has no visual representation, and only the view that it manages provides a visual canvas.

Remember:

1. Although the Windows UIWindow is also UIView, it can not be set in the way of handling ordinary uiview;

2. The UIView view uses initWithFrame: initialization, and its uiviewcontroller is initialized directly using the Init class method.

3. The Uiviewcontroller instance is responsible for setting the appearance of the view and the child views it displays.

Uinavigationcontroller class
1. The navigation controller uses built-in animations to switch between views;

2. The navigation controller automatically constructs and processes the back button;

3. The navigation controller provides a simple menu bar to help users with custom controls.

4. Each navigation controller has a root view controller Rootviewcontroller, which is the base of the "navigation pop-up stack" and is the root.

5. You can set a specific controller to root by calling the Initwithrootviewcontroller: method.

As is common:

Uinavigationcontroller *nav = [[Uinavigationcontroller alloc] Initwithrootviewcontroller:[[myviewcontroller alloc] Init]]; [Window AddSubview:nav.view];



Uinavigationcontroller How to push and eject the view controller?

  • Using pushviewcontroller:animated: A new controller can be pushed in to add new items to the navigation stack. ( remember: the navigation bar controller does not add a view in, this navigation bar is meaningless!) )
    Create a navigation controller uinavigationcontroller *anav = [[Uinavigationcontroller alloc] init];//Create a view controller to be pushed in, Then add this view controller to the navigation bar and display uiviewcontroller *aview = [[Uiviewcontroller alloc] initwithnibname: (*xib filename *)]; [Anav Pushviewcontroller:aview Animated:no]; This is assumed to be the first view of the navigation bar, so do not animate.
    When the replication code is pushed in, the new view controller slides from the right into the screen (assuming Animated:yes). Left-pointing back button appears to return to the previous step, and the Back button uses the title of the previous view controller.
  • The Back button, which pops up to the top level view controller, is automatically generated and processed without user intervention.
  • You can use Popviewcontrolleranimated:bool to eject the current view controller and display the previous view to the left.
  • You can use poptoviewcontroller:animated: pops up to the specified view controller, which is not necessarily the previous one.
  • You can use Poptorootviewcontrolleranimated:bool to eject directly to the root view controller.
  • The button to set the navigation bar is not to set the navigation bar itself. Everything is done inside the Uiviewcontroller subclass of the push request and the related navigation bar customization (for example, right-click button).

    The navigation bar can change the style of the bar or its color by directly accessing the Navigationbar property:
    Self.navigationController.navigationBar.barStyle = uibarstyleblacktranslucent;
    Tips: Uiviewcontroller has a property of Navigationcontroller, if the current Viewcontroller is in the stack of a navigationcontroller (that is, it is pushed over), This property of the view controller points to that navigationcontroller, otherwise nil.

    To add or modify a navigation bar button, use the Uinavigationitem abstract class. It describes what is displayed on the navigation bar, and just uiviewcontroller another navigation item property Navigationitem including the left column button (Leftbarbuttonitem), The right column button (Rightbarbuttonitem) and the column heading (title), the view used to display the caption (Titleview), and the Back button (Backbarbuttonitem) and the Hide Back button (Hidesbackbutton) for navigating backwards from the current view.

    Note: For the navigation bar customization, use the child view controller instead of the title property of the navigation item for the simplest way to customize the actual caption:
    Self.title = @ "Hello";
    Self.title = [[[NSBundle Mainbundle] infodictionary] objectforkey:@ "Cfbundlename"]; Enables the caption to automatically reflect the running application name

    The navigation controller loads the modal view controller:
    Typically, modal view controllers are used to pick up data. After sending the presentmodalviewcontroller:animated: message, a new view controller (actually a modalviewcontroller) slides to the screen and controls, Until you use dismissmodalviewcontrolleranimated: Hide it to regain control.

    for the navigation controller, the Viewwillappear method is not the result, to implement the Uinavigationcontrollerdelegate delegate method willshowviewcontroller:animated: To achieve the purpose .

    Uitabbarcontroller class
    The tab class allows users to move between multiple view controllers and customize the bar at the bottom of the screen. Provides one-click access to different views while providing a more button to the screen selected by the user and the screen for editing the bottom bar.
    The convenience of the tab class is that instead of pushing and ejecting the view as if it were a navigation bar, a series of controllers (each of which can be Uiviewcontroller, Uinavigationcontroller, Uitableviewcontroller or any other type of view controller) and add it to the tab bar by setting the Viewcontrollers property of the bar so that each tab corresponds to an attempt to the controller.

    First, create Uitabbarcontroller

    • Commonly created in the applicationdidfinishlaunching: method of the application delegate class, which typically provides the root view for the application window.
      Of course, creating Uitabbarcontroller in the application delegate Appdelegate class is equivalent to creating an engineering project based on the tab bar. However, depending on the situation, we can create Uitabbarcontroller instance objects directly in a separate view controller, such as customizing a Controller class Viewswitcherviewcontroller for view switching, You can create the required tabbarcontroller in the Viewdidload method.
    • Override the Init method in the view controller that implements the Uitabbarcontrollerdelegate delegate to customize the Uitabbaritem entry.
      code One is made by the Initwithnibname: method to load a specific view controller and customize the Tabbaritem style appearance in that controller.
      -(ID) init {   if (self = [Super initwithnibname:@ "Myviewcontroller" Bundle:nil]) {       self.title = @ "My View Controlle R ";              UIImage *animage = [UIImage imagenamed:@ "Myimage.png"];       Uitabbaritem *theitem = [[Uitabbaritem alloc] initwithtitle:@ "Home" Image:animage tag:0];       Self.tabbaritem = Theitem;       [Theitem release];   }   return self;}
      code Two We can also override the Init method directly inside the specific view controller.
      -(ID) init {   if ([Super init]! = nil) {       Uitabbaritem *item = [[Uitabbaritem alloc] initwithtitle:@ "Home" Image:[u IImage imagenamed:@ "Myimage.png"] tag:0];          Self.tabbaritem = Item;          [item release];   }   return self;}
    • Implement the required delegate methods so that Uitabbarcontroller can trigger these callback methods normally.
      Tabbarcontroller:didselectviewcontroller: is when the user selects a new tab, the Controller sends the message.
      -(void) Tabbarcontroller: (Uitabbarcontroller *) Tabbarcontroller Didselectviewcontroller: (Uiviewcontroller *) viewcontroller{    //snap SelectedIndex to determine the currently selected tab    nsnumber *tabnumber = [NSNumber numberwithint:[ Tabbarcontroller SelectedIndex]];   Using the iphone built-in user default system nsuserdefaults, use Setobject:forkey: Set values for keywords   [[nsuserdefaults Standarduserdefaults] SetObject : Tabnumber forkey:@ "Selectedtab"];   [[Nsuserdefaults standarduserdefaults] synchronize];   tab icon Item upper right corner red small red circle number hint   viewController.tabBarItem.badgeValue = [NSString stringwithformat:@ "%d", 80];}

IOS Cocoa Programming in view Controller and view class (GO)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.