zoukankan      html  css  js  c++  java
  • Objetive C view

    Creating the View

    One label and two buttons

    One butoon will generate the seed, another button will generate the random number, and the label shows the random number generated by the app.
    Drag a Label from the library Pane Controls section to the View Window.

    Drag two rounded rect buttons

    Click the top button and label the button Seed Random Number Generator

    quickly and easy connect our Outlests and Actions to our code.

    Click the Assistant Editor icon  at the top right of the screen.This will display the .h file for the XIB file we are working on ,

    Using Outlets

    Insert curly brackets for your instance variables.

    .h file

    A popup window will appear .This enables us to name and specify the type of Outlet.

    @interface ViewController : UIViewController

    {

      IBOutlet UILabel *randomNumber;

    }

    @end

    As a reminder,outlets(pointers) are declared in our object's interface file and connected to specific instance variables.

    simply as an outlet.

    Outlets signal your controller that this instance variable is a pointer to another object that is set up in Intrface Builder, we can connect these instance variables to the appropriate object.

    Connecting Actions and Objects

    connect the object actions to the buttons

    Control-Drag from the Seed Random Number Generator button to below the last curly bracket and drop.

    connection is an Action

    Repeat Step 8 for the Generate Random Number button.

    #import <UIKit/UIKit.h>

    @interface ViewController : UIViewController

    {

      IBOutlet UILabel *randomNumber;

    }

    _ (IBAction)seed:(id)sender;

    _(IBAction)generate:(id)sender;

    @end

    Implementation File

    ViewController.m file and complete the seed: and generate: method

    _ (IBAction)seed:(id)sender{

      srandom(time(NULL));

      [randomNumber setText: @"Generator seeded"];

    }

    _ (IBAction)generate:(id)sender {

      int generated;

      generated = (random() % 101);

      [randomNumber setText:[NSString stringWithFormat:@"%i",generated]];

          set the UILabel value in your view.

        

    }

    sets the UILabel value in your view.

    XIB files

    Model-View-Controller

    Architectural pattern

    Human interface guidelines(HIGS)

    Outlets

    Actions

  • 相关阅读:
    不注意的小问题
    Hibernate、Spring和Struts工作原理及使用理由
    正则表达式贪婪与非贪婪模式
    Springmvc构造RESTful详细讲解
    正则表达式贪婪与非贪婪模式1
    BOJ二叉排序树的后序遍历
    qsort()应用大全
    辗转相除法求最大公约数(C语言)
    九度题目1014:排名 (结构体多级排序)
    BOJ第三题:二叉树前序遍历
  • 原文地址:https://www.cnblogs.com/yushunwu/p/2626051.html
Copyright © 2011-2022 走看看