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

  • 相关阅读:
    模拟死锁
    B站学习斯坦福大学Swift 语言教程 iOS11 开发【第一集】踩到的几个坑(XCode 13.2.1版本)
    数学之美番外篇:平凡而又神奇的贝叶斯方法
    joj 1753: Street Numbers
    二叉树的三种遍历(递归+非递归)
    joj 1905: Freckles
    joj 2630: A Pair of Graphs(同构图的判定)
    vue3.x 中获取dom元素
    defineProperty 和 Proxy 的区别
    vue 按钮的防抖和节流
  • 原文地址:https://www.cnblogs.com/yushunwu/p/2626051.html
Copyright © 2011-2022 走看看