zoukankan      html  css  js  c++  java
  • IOS Note

    OutletActionViewController.h

    #import <UIKit/UIKit.h>
    
    @interface OutletActionViewController : UIViewController
    {
        IBOutlet UITextField *txtName;
    }
    
    // expose the outlet as a property
    @property (nonatomic, retain) UITextField *txtName;
    
    // declare the action
    - (IBAction) btnClicked: (id) sender;
    
    @end

    OutletActionViewController.m

    #import "OutletActionViewController.h"
    
    @implementation OutletActionViewController
    
    // synthesize the property
    @synthesize txtName;
    
    // display text of the textbox in the alert
    - (IBAction) btnClicked: (id) sender {
        NSString *str = 
            [[NSString alloc] initWithFormat: @"Hello, %@", txtName.text];
        
        UIAlertView *alert =
        [[UIAlertView alloc] 
        initWithTitle: @"Hello"
        message: str
        delegate: self
        cancelButtonTitle: @"OK"
        OtherButtonTitles: nil];
        
        [alert show];
        [str release];
        [alert release];
    }
    
    - (void) dealloc {
        // release the outlet
        [txtName release];
        [super dealloc];
    }

    如何添加关联

    -------------------------------------------------------------------------------------------

    Outlet添加:
    按Control同时将File's Owner拖放到IBOutlet在视图中所在的对象(eg: Text Field)
    File's Owner --> Outlet

    Action添加:
    按Control同时将事件需要触发的控件(eg: Round Rect Button)拖放到File's Owner
    选择动作的指定函数
    Action --> File's Owner

  • 相关阅读:
    第09组 Beta冲刺(2/5)
    第09组 Beta冲刺(3/5)
    第09组 Beta冲刺(4/5)
    第09组 Beta冲刺(5/5)
    第09组 Beta冲刺(1/5)
    SDN课程阅读作业(2)
    C语言I作业07
    C语言I博客作业05
    C语言I博客作业04
    C语言I博客作业03
  • 原文地址:https://www.cnblogs.com/davidgu/p/3467794.html
Copyright © 2011-2022 走看看