从零开始iOS8编程【iOS开发常用控件】
-(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我们需要在h文件中实现UIActionSheetDelegate协议。
该方法是ActionSheet消失的时候调用。
@interface HelloHaoMengZhuViewController : UIViewController { UITextField *txtField; UIActivityIndicatorView * myActivityView; IBOutlet UIProgressView *Progress; NSTimer *timer; }
-(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
-(IBAction)onClickButton2: (id)sender { if ([myActivityView isAnimating]) { [myActivityView stopAnimating]; } else { [myActivityView startAnimating]; } }
-(IBAction)start{ Progress.progress = 0.0; timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(update) userInfo:nil repeats:YES]; }
NSTimer是可以隐式地启动一个线程,
scheduledTimerWithTimeInterval指定线程要休眠多少时间调用一次,
-(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烦范围。
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。