您的位置:首页 > 产品设计 > UI/UE

【UIKit】页面视图间的切换Alert,Sheet等使用

2014-04-12 11:28 549 查看


代码

【Alert】

代码:

1.加入协议

<UIAlertViewDelegate,UIActionSheetDelegate>


2.

-(IBAction)btnShowAlertView:(id)sender


{
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"标题"
message:@"对话框的内容"
delegate:self
cancelButtonTitle:@"关闭"
otherButtonTitles:@"其他1",@"其他2",nil];
[alert show];
[alert release];
}


3.如何获取到点击按钮的tag

#pragma mark - UIAlertViewDelegate可以获取到所按的按钮的index
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSLog(@"actionSheet buttonIndex = %i", buttonIndex);
}


【sheet】

1.加入协议

<UIAlertViewDelegate,UIActionSheetDelegate>


2.

-(IBAction)btnShowActionSheet:(id)sender


{
UIActionSheet *actions=[[UIActionSheet alloc]initWithTitle:@"标题"
delegate:self
cancelButtonTitle:@"关闭"
destructiveButtonTitle:nil
otherButtonTitles:@"其他1",@"其他2", nil];
[actions showInView:self.view];
[actions release];
}


3.获取到sheet点击按钮的index

#pragma mark - UIActionSheetDelegate
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSLog(@"actionSheet buttonIndex = %i", buttonIndex);
}


【SVStatusHUD】素材 代码

-(IBAction)btnStatusHUD:(id)sender


{
[SVStatusHUD showSuccessWithStatus:@"授权已过期!"];
}


操作步骤:

1.在.m中引用

#import "SVStatusHUD.h"


2.加入代码

-(IBAction)btnStatusHUD:(id)sender
{
[SVStatusHUD showSuccessWithStatus:@"授权已过期!"];
}


【Xib页面间的切换】

-(IBAction)btnRegisterClicked:(id)sender
{
if(secondViewController==nil)
{
secondViewController=[[SecondViewController alloc]initWithNibName:nil bundle:nil];
}

[self.view.superview addSubview:secondViewController.view];
[self.view removeFromSuperview];
}


【嵌套的Alert】

#pragma mark -循环提问
-(IBAction)btnShowAlertView:(id)sender
{
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"标题"
message:@"对话框的内容"
delegate:self
cancelButtonTitle:@"关闭"
otherButtonTitles:@"其他1",@"其他2",nil];
alert.tag=1;    // 【使用tag值进行嵌套跳出】
[alert show];
[alert release];
}

#pragma mark - UIAlertViewDelegate
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(alertView.tag==1)      // 【判断如果tag==1,那么就继续第二层,然后在本方法中设置tag为2,当再次进入此循环后,tag!=1就可以跳出循环了】
{
NSLog(@"actionSheet buttonIndex = %i", buttonIndex);
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"标题2"
message:@"对话框的内容2"
delegate:self
cancelButtonTitle:@"关闭2"
otherButtonTitles:@"第二层2",@"第二层1",nil];
alert.tag=2;
[alert show];
[alert release];
}
else
  {
   NSLog(@"actionSheet buttonIndex = %i", buttonIndex);
  }
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐