自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

iPhone教程 對(duì)話框與輸入框按鈕響應(yīng)界面

移動(dòng)開發(fā) iOS
本文介紹的是iPhone教程 對(duì)話框與輸入框按鈕響應(yīng)界面,主要是界面的操作,我們先來看內(nèi)容。

iPhone教程 對(duì)話框與輸入框按鈕響應(yīng)界面是本文要介紹的內(nèi)容,主要來介紹一下iphone中UIButton 與UITextField簡單的界面彈出對(duì)話框以及按鈕的響應(yīng) 。項(xiàng)目需求:實(shí)現(xiàn)兩個(gè)按鈕 ,兩個(gè)文本框點(diǎn)擊按鈕在文本輸入框中顯示從那個(gè)按鈕中點(diǎn)進(jìn)去的信息。如圖:

iPhone教程 對(duì)話框與輸入框按鈕響應(yīng)界面

聲明類

  1. //  
  2. //  testViewController.h  
  3. //  test  
  4. //  
  5. //  Created by  宣雨松 on 11-7-5.  
  6. //  Copyright 2011年 __MyCompanyName__. All rights reserved.  
  7. //  
  8.  
  9. #import <UIKit/UIKit.h> 
  10.  
  11. // 在ViewController中實(shí)現(xiàn)UIAlertViewDelegate接口 用來監(jiān)聽彈出框 確定與取消  
  12. @interface testViewController : UIViewController <UIAlertViewDelegate> 
  13. {  
  14.     //定義了一個(gè)按鈕buttonA  
  15.     IBOutlet UIButton *buttonA;  
  16.     //定義了一個(gè)文本框A  
  17.     IBOutlet UITextField *textFieldA;   
  18.     //定義了一個(gè)按鈕buttonB      
  19.     IBOutlet UIButton *buttonB;      
  20.     //定義了一個(gè)文本框B      
  21.     IBOutlet UITextField *textFieldB;   
  22. }      
  23. //聲明A按鈕被按下的一個(gè)方法(IBAction) 相當(dāng)于(void)  
  24. -(IBAction)bttonAPressed:(id)text;      
  25. //聲明B按鈕被按下的一個(gè)方法  
  26. -(IBAction)bttonBPressed:(id)text;  
  27. //注意這兩個(gè)方法是用來綁定在空間上 稍后我給大家介紹如何綁定  
  28. @end 

接下來我介紹一下控件與方法的綁定 比如我須要點(diǎn)擊按鈕A 后調(diào)用我自己寫的方法 bttonApressed() 我需要點(diǎn)中按鈕后 右側(cè)出現(xiàn)視圖欄 點(diǎn)中 New Referencing Outlet 拉出一條線拖到 左側(cè)上***個(gè)菱形上后 選 buttonA 表示這個(gè)butonA 與代碼中聲明的buttonA關(guān)聯(lián)上了 然后在點(diǎn)中Touch Up Inside 拉出一條線 依然拖動(dòng)到左側(cè)***個(gè)菱形上選擇bttonAPressed()方法 這表示點(diǎn)擊按鈕buttonA后 會(huì)調(diào)用自己寫的方法 bttonAPressed()  簡單吧 。 Android 開發(fā)的可視化布局卻是不如IPHONE開發(fā)的布局,J2ME 就更不行了。如圖:

iPhone教程 對(duì)話框與輸入框按鈕響應(yīng)界面

實(shí)現(xiàn)類

  1. //  
  2. //  testViewController.m  
  3. //  test  
  4. //  
  5. //  Created by  宣雨松 on 11-7-5.  
  6. //  Copyright 2011年 __MyCompanyName__. All rights reserved.  
  7. //  
  8.  
  9. #import "testViewController.h"  
  10.  
  11. @implementation testViewController  
  12.  
  13. - (void)dealloc  
  14. {  
  15.     [super dealloc];  
  16. }  
  17.  
  18. - (void)didReceiveMemoryWarning  
  19. {  
  20.     // Releases the view if it doesn't have a superview.  
  21.     [super didReceiveMemoryWarning];  
  22.       
  23.     // Release any cached data, images, etc that aren't in use.  
  24. }  
  25.  
  26. #pragma mark - View lifecycle  
  27.  
  28. /*  
  29. // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.  
  30. - (void)viewDidLoad  
  31. {  
  32.     [super viewDidLoad]  
  33. }  
  34. */  
  35. UIAlertView * alertA;  
  36. - (void)bttonAPressed:(id)text  
  37. {  
  38.     //在這里實(shí)現(xiàn)了按鈕A綁定的方法   
  39.     //這里說一下nil  這個(gè)東西就好比java 語言中的 null   
  40.     alertA= [[UIAlertView alloc] initWithTitle:@"我的視圖" message:@"點(diǎn)開了A彈出對(duì)話框" 
  41. delegate:self cancelButtonTitle:@"確定" otherButtonTitles: nil];  
  42.     //objectiveC開發(fā)中調(diào)用方法是用"[]" 例如: [alertA addButtonWithTitle:@"取消"];  
  43.     //如果是為方法賦值則類似java 對(duì)象.成員 例如 :textFieldA.text      
  44.     //添加了一個(gè)取消按鈕  
  45.     [alertA addButtonWithTitle:@"取消"];  
  46.     //將這個(gè)UIAlerView 顯示出來  
  47.     [alertA show];  
  48.     //objective-C 不像java 有自己的垃圾回收機(jī)制 所以我們?cè)诰帉懗绦蛑幸欢ㄒ⒁忉尫艃?nèi)存 從一開始就養(yǎng)成良好習(xí)慣  
  49.     [alertA release];  
  50.  
  51. }  
  52.   UIAlertView * alertB;  
  53. -(void)bttonBPressed:(id)text  
  54. {  
  55.     //在這里實(shí)現(xiàn)了按鈕B綁定方法  
  56.     alertB = [[UIAlertView alloc] initWithTitle:@"我的視圖" message:@"點(diǎn)開了B彈出對(duì)話框" 
  57. delegate:self cancelButtonTitle:@"確定" otherButtonTitles: nil];  
  58.     [alertB show];  
  59.     [alertB release];  
  60. }  
  61. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex  
  62. {  
  63.    //在這里添加對(duì)話框按鈕響應(yīng)事件 根據(jù)不同窗口判斷  
  64.     if(alertView == alertA)  
  65.     {  
  66.         switch (buttonIndex)   
  67.         {  
  68.         case 0:  
  69.             textFieldA.text = @"A窗口中點(diǎn)擊確認(rèn)按鈕";  
  70.             break;  
  71.         case 1:  
  72.             textFieldA.text = @"A窗口點(diǎn)擊取消按鈕";  
  73.         default:  
  74.             break;  
  75.         }  
  76.     }else if (alertView == alertB)  
  77.     {  
  78.         textFieldB.text = @"B窗口點(diǎn)擊確定按鈕";      
  79.     }  
  80. }  
  81. - (void)viewDidUnload  
  82. {  
  83.     [super viewDidUnload];  
  84.     // Release any retained subviews of the main view.  
  85.     // e.g. self.myOutlet = nil;  
  86. }  
  87. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation  
  88. {  
  89.     // Return YES for supported orientations  
  90.     return (interfaceOrientation == UIInterfaceOrientationPortrait);  
  91. }  
  92. @end 

小結(jié):iPhone教程 對(duì)話框與輸入框按鈕響應(yīng)界面的內(nèi)容介紹我那了,希望本文對(duì)你有所幫助。

本文轉(zhuǎn)自 http://blog.csdn.net/xys289187120/article/details/6586961--

責(zé)任編輯:zhaolei 來源: 互聯(lián)網(wǎng)
相關(guān)推薦

2011-07-01 11:33:00

Qt 模態(tài) 非模態(tài)

2009-12-28 13:47:35

WPF對(duì)話框

2009-12-28 14:32:31

WPF窗體對(duì)話框

2009-12-11 15:35:50

PHP彈出對(duì)話框

2010-01-28 16:55:26

Android對(duì)話框

2011-07-21 15:50:42

jQuery Mobi頁面對(duì)話框

2023-07-05 08:15:41

按鈕PRSHT.H函數(shù)

2020-09-24 14:06:19

Vue

2009-09-03 17:44:22

iPhone程序開發(fā)

2010-01-11 09:33:32

VB.NET對(duì)話框調(diào)用

2009-12-29 15:24:48

WPF對(duì)話框

2011-11-23 09:47:36

Winform

2011-05-20 16:49:21

VB.NET

2013-12-27 14:10:36

Android開發(fā)Android應(yīng)用Transform

2010-01-22 16:27:19

VB.NET關(guān)于對(duì)話框

2011-06-02 10:37:02

Android 對(duì)話框

2012-12-03 10:47:54

WebJQuery控件

2011-08-15 10:15:00

iPhone開發(fā)警告框

2022-03-02 15:47:57

Dialog組件UI設(shè)計(jì)鴻蒙

2021-07-11 07:34:23

Windows 11操作系統(tǒng)微軟
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)