從零開始iOS8編程【iOS開發常用控制項】

來源:互聯網
上載者:User

標籤:ios8編程   對話方塊   控制項   線程   等待控制項   

郝萌主傾心貢獻,尊重作者的勞動成果,請勿轉載。

如果文章對您有所協助,歡迎給作者捐贈,支援郝萌主,捐贈數額隨意,重在心意^_^ 

我要捐贈: 點擊捐贈

Cocos2d-X源碼下載:點我傳送


AlertView控制項彈出對話方塊:修改HelloHaoMengZhu項目代碼, 添加AlertView:
-(IBAction)testAlert {NSString *str = [[NSString alloc] initWithFormat:@"Hello, %@",txtField.text];UIAlertView *alert = [[UIAlertView alloc]  initWithTitle:@"提示" message:str  delegate:self  cancelButtonTitle:@"Ok"  otherButtonTitles:nil];[str release];[alert show];[alert release];    }- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {NSLog(@"%@",@"Ok" );}


ActionSheet控制項
ActionSheet和AlertView比較相似都是給使用者一個提示資訊。 它是從底部彈出。它通常用於確認潛在的危險或不能撤消的操作, 如刪除一個資料。
為了使用ActionSheet我們需要在h檔案中實現UIActionSheetDelegate協議。 其中, 我們常常需要實現:actionSheet:didDismissWithButtonIndex:
該方法是ActionSheet消失的時候調用。
修改Hello-.h檔案
@interface HelloHaoMengZhuViewController : UIViewController{    UITextField *txtField;    UIActivityIndicatorView * myActivityView;        IBOutlet UIProgressView *Progress;NSTimer *timer;}
在Hello_Controller.h檔案中添加協議UIActionSheetDelegate:
-(IBAction)testActionSheet {NSString *str = [[NSString alloc] initWithFormat:@"Hello, %@",txtField.text];UIActionSheet *action = [[UIActionSheet alloc] initWithTitle:@"提示"delegate:self   cancelButtonTitle:@"取消"  destructiveButtonTitle:@"確定"   otherButtonTitles:nil];[str release];[action showInView:self.view];[action release];    }- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex {if (buttonIndex == [actionSheet destructiveButtonIndex]) {NSLog(@"%@",@"確定" );} else if (buttonIndex == [actionSheet cancelButtonIndex]) {NSLog(@"%@",@"取消" );}}


等待有關控制項
對於一些費時的處理, 需要使用一些等待控制項消除使用者心裡等待的時間。
等待有關的控制項有:
UIActivityIndicatorView
UIProgressView
設計UI:

UIActivityIndicatorView的實現
-(IBAction)onClickButton2: (id)sender {if ([myActivityView isAnimating]) {[myActivityView stopAnimating];} else {[myActivityView startAnimating];}}


UIProgressView的實現
-(IBAction)start{Progress.progress = 0.0;timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(update) userInfo:nil repeats:YES];}
代碼說明:
NSTimer是可以隱式地啟動一個線程,
scheduledTimerWithTimeInterval指定線程要休眠多少時間調用一次, selector所指定的方法update。
-(void)update{Progress.progress = Progress.progress + 0.1;if (Progress.progress == 1.0) {[timer invalidate];UIAlertView *alert = [[UIAlertView alloc]  initWithTitle:@"任務通知"  message:@"波多野結衣.avi 下載完成!"  delegate:self  cancelButtonTitle:@"OK"  otherButtonTitles:nil];[alert show];[alert release];}}
代碼說明:
UIProgressView控制項的progress屬性是0.0~1.0煩範圍。 0.0時候在開始的位置, 1.0時候是進度到了100%。


郝萌主傾心貢獻,尊重作者的勞動成果,請勿轉載。

如果文章對您有所協助,歡迎給作者捐贈,支援郝萌主,捐贈數額隨意,重在心意^_^ 

我要捐贈: 點擊捐贈

Cocos2d-X源碼下載:點我傳送


從零開始iOS8編程【iOS開發常用控制項】

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.