博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
IOS Note - Outlet(插座) & Action(动作)
阅读量:7005 次
发布时间:2019-06-27

本文共 1282 字,大约阅读时间需要 4 分钟。

OutletActionViewController.h

#import 
@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

 

转载于:https://www.cnblogs.com/davidgu/p/3467794.html

你可能感兴趣的文章