聲明屬性
atom
@interface LoginControler() <UITextFieldDelegate> @property (weak, nonatomic) IBOutlet UITextField *userName; @end
1,代理方式代理
-(void) viewDidLoad { _userName.delegate = self; //添加代理 } -(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { NSLog(@"%@", textField.text); return true; //若是NO就不會顯示 }
2,通知 code
這種方式在通知完後還須要釋放,麻煩,用的少orm
-(void) viewDidLoad { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textChange) name:UITextFieldTextDidChangeNotification object:nil]; //addObserver:self 監聽者對象 //name 監聽的改變對象的方法 //object 監聽的對象 nil 所有監聽 } -(void)textChange { NSLog(@"%@", _userName.text); } -(void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; //移除監聽 }
3,動態添加執行方法
server
-(void) viewDidLoad { [_userName addTarget:self action:@selector(textChange) forControlEvents:UIControlEventEditingChanged]; //forControlEvents 觸發事件 } -(void)textChange { NSLog(@"%@", _userName.text); }
switch 開關的方法對象
- (IBAction)loginSwith:(UISwitch *)sender { if (sender.isOn ) { [_Test setOn:YES animated:YES]; NSLog(@"開"); } else { [_Test setOn:NO animated:YES]; NSLog(@"關"); } }
UIActionSheet 底部彈出提示框事件
UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"拍照"otherButtonTitles:@"照相",nil]; [sheet showInView:self.view]; //initWithTitle 提示欄 //delegate 代理者 //cancelButtonTitle 取消按鈕 //destructiveButtonTitle 從上往下的第一個按鈕 //otherButtonTitles 第二個按鈕 -(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{ NSLog(@"%ld",buttonIndex); }
UIAlertView 提示框rem
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"標題" message:@"內容" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"肯定", nil]; [alert show];
board 跳轉方法get
1, //獲取storyboard UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; //獲取想要的viewControl UIViewController *control = [storyboard instantiateViewControllerWithIdentifier:@"phoneStoryboard"]; //push 跳轉 [[self navigationController]pushViewController:control animated:YES]; 2, [self performSegueWithIdentifier:@"phonesugue" sender:nil]; //performSegueWithIdentifier 爲鏈接跳轉sugue的id