UIAlertView的实现

转载 2012年03月26日 13:02:29

1、  在头文件中设置委托

@interface CardEdit : UIViewController  <UIPickerViewDataSource, UIPickerViewDelegate,UIAlertViewDelegate,UITextFieldDelegate> {

         UIPickerView *m_pPickerView

         NSArray *m_data

         NSIntegerchoice;

         NSString *AlertName;

         NSString *GroupName;

         UILabel *llabelGroup;

         UITextField *ltextGroup;

 

}

注意:红色是指定的委托。

 

 

2、 实现多个UIAlertView在同一个函数中实现事件触发。

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

{

         if(AlertName==@"增加名片")

         {

                   if(buttonIndex==0)

                   {

                           

                   }

                   else {

                            CardInformation *myCard=[[CardInformationalloc] init]; 

                            myCard.groupkey=self.choice;

                            myCard.cardkey=10001;

                            [self.viewaddSubview:myCard.view];

                   }

 

                  

         }

         if(AlertName==@"修改群组")

         {

                   if(buttonIndex==0)

                   {

                           

                   }

                   else {

                            GroupName=ltextGroup.text;

                            NSString *path = [[NSBundlemainBundle] pathForResource:@"MyData"ofType:@"plist"];

                            NSMutableDictionary *dict = [[NSMutableDictionaryalloc] initWithContentsOfFile:path];

                           

                            NSArray *temp = [dict allKeys];

                            NSString *temp2 = [temp objectAtIndex:choice];

                            NSMutableDictionary *mydict = [dict objectForKey:temp2];

                           

                            [dict setObject:mydict forKey:GroupName];

                            [dict removeObjectForKey:temp2];

                            [dict writeToFile:path atomically:YES];

                           

                           

                           

                            UIAlertView *alertView=[[UIAlertViewalloc] initWithTitle:@"修改群组成功"message:@"恭喜您,修改群组成功!"delegate:selfcancelButtonTitle:@"取消"otherButtonTitles:@"确认",nil];

                            [alertView show];  //显示弹出框

                            [alertView setFrame:CGRectMake(alertView.frame.origin.x,alertView.frame.origin.y,alertView.frame.size.width , alertView.frame.size.height)];

                       AlertName = @"0";

                           

                   }

                  

         }

         if(AlertName==@"增加群组")

         {

                   if(buttonIndex==0)

                   {

                           

                   }

                   else {

                            GroupName=ltextGroup.text;

                            NSString *path = [[NSBundlemainBundle] pathForResource:@"MyData"ofType:@"plist"];

                            NSMutableDictionary *dict = [[NSMutableDictionaryalloc] initWithContentsOfFile:path];

                            NSMutableDictionary *mydict = [[NSMutableDictionaryalloc]init];

                            [dict setObject:mydict forKey:GroupName];

                            NSLog(@"%@",GroupName);

                            [dict writeToFile:path atomically:YES];

                           

                            UIAlertView *alertView=[[UIAlertViewalloc] initWithTitle:@"增加群组成功"message:@"恭喜您,增加群组成功!"delegate:selfcancelButtonTitle:@"取消"otherButtonTitles:@"确认",nil];

                            [alertView show];  //显示弹出框

                            [alertView setFrame:CGRectMake(alertView.frame.origin.x,alertView.frame.origin.y,alertView.frame.size.width , alertView.frame.size.height)];

                       AlertName = @"0";

                           

                   }

                  

         }

         if(AlertName==@"删除群组")

         {

                   if(buttonIndex==0)

                   {

                           

                   }

                   else {

                            NSString *path = [[NSBundlemainBundle] pathForResource:@"MyData"ofType:@"plist"];

                            NSMutableDictionary *dict = [[NSMutableDictionaryalloc] initWithContentsOfFile:path];

                            NSArray *temp = [dict allKeys];

                            NSString *temp2 = [temp objectAtIndex:choice];

                            [dict removeObjectForKey:temp2];

                            [dict writeToFile:path atomically:YES];

                           

                            UIAlertView *alertView=[[UIAlertViewalloc] initWithTitle:@"删除群组成功"message:@"恭喜您,删除群组成功!"delegate:selfcancelButtonTitle:@"取消"otherButtonTitles:@"确认",nil];

                            [alertView show];  //显示弹出框

                            [alertView setFrame:CGRectMake(alertView.frame.origin.x,alertView.frame.origin.y,alertView.frame.size.width , alertView.frame.size.height)];

                       AlertName = @"0";

                           

                   }

                  

         }

         if(AlertName==@"备份名片")

         {

                   if(buttonIndex==0)

                   {

                           

                   }

                   else {

                            NSString *path = [[NSBundlemainBundle] pathForResource:@"CardInfo"ofType:@"plist"];

                            NSMutableDictionary *dict = [[NSMutableDictionaryalloc] initWithContentsOfFile:path];

                            NSString *path2 = [[NSBundlemainBundle] pathForResource:@"CardInfo2"ofType:@"plist"];

                           

                            NSString *path3 = [[NSBundlemainBundle] pathForResource:@"MyData"ofType:@"plist"];

                            NSMutableDictionary *dict2 = [[NSMutableDictionaryalloc] initWithContentsOfFile:path3];

                            NSString *path4 = [[NSBundlemainBundle] pathForResource:@"MyData2"ofType:@"plist"];

                            [dict writeToFile:path2 atomically:YES]; 

                            [dict2 writeToFile:path4 atomically:YES];

                           

                            UIAlertView *alertView=[[UIAlertViewalloc] initWithTitle:@"备份成功"message:@"恭喜您,备份名片成功!"delegate:selfcancelButtonTitle:@"取消"otherButtonTitles:@"确认",nil];

                            [alertView show];  //显示弹出框

                            [alertView setFrame:CGRectMake(alertView.frame.origin.x,alertView.frame.origin.y,alertView.frame.size.width , alertView.frame.size.height)];

                       AlertName = @"0";

                            }

                  

         }

         if(AlertName==@"还原名片")

         {

                   if(buttonIndex==0)

                   {

                           

                   }

                   else {

                                                       

                            NSString *path2 = [[NSBundlemainBundle] pathForResource:@"CardInfo2"ofType:@"plist"];

                            NSMutableDictionary *dict = [[NSMutableDictionaryalloc] initWithContentsOfFile:path2];

                            NSString *path = [[NSBundlemainBundle] pathForResource:@"CardInfo"ofType:@"plist"];

                            [dict writeToFile:path atomically:YES];

                           

                            NSString *path4 = [[NSBundlemainBundle] pathForResource:@"MyData2"ofType:@"plist"];

                            NSMutableDictionary *dict2 = [[NSMutableDictionaryalloc] initWithContentsOfFile:path4];

                            NSString *path3 = [[NSBundlemainBundle] pathForResource:@"MyData"ofType:@"plist"];

                            [dict2 writeToFile:path3 atomically:YES];

                           

                            UIAlertView *alertView=[[UIAlertViewalloc] initWithTitle:@"还原成功"message:@"恭喜您,还原名片成功"delegate:selfcancelButtonTitle:@"取消"otherButtonTitles:@"确认",nil];

                            [alertView show];  //显示弹出框

                            [alertView setFrame:CGRectMake(alertView.frame.origin.x,alertView.frame.origin.y,alertView.frame.size.width , alertView.frame.size.height)];

                            AlertName = @"0";

                   }

                  

         }

 

}

 

 

 

 

3、  在程序中使用UIAlertView,并且实现在UIAlertView上增加各种组件

 

UIAlertView *alertView=[[UIAlertViewalloc] initWithTitle:@"增加名片"message:nildelegate:selfcancelButtonTitle:@"取消"otherButtonTitles:@"确定",nil];

         alertView.delegate=self;

         [alertView show];  //显示弹出框

         [alertView setFrame:CGRectMake(alertView.frame.origin.x,alertView.frame.origin.y,alertView.frame.size.width , alertView.frame.size.height+200)];

        

         for (UIView *Outlet in [alertView subviews]) {    //将按钮放置在弹出框的下面

        if(![Outlet isKindOfClass:[UITextFieldclass]]&&![Outlet isKindOfClass:[UILabelclass]])

        {

            UIButton* button = (UIButton*)Outlet;

            button.frame = CGRectMake(button.frame.origin.x, button.frame.origin.y+160,button.frame.size.width , button.frame.size.height);

        }

    }

         self.llabelGroup = [[UILabelalloc] initWithFrame:CGRectMake(20, 40, 140, 20)];

    llabelGroup.text = @"选择群组:";

    llabelGroup.backgroundColor = [UIColorclearColor];

    llabelGroup.textColor = [UIColorwhiteColor];

    [alertView addSubview:llabelGroup];

    [llabelGrouprelease];

        

         m_pPickerView=[[UIPickerViewalloc] init];

         m_pPickerView.showsSelectionIndicator = YES;

         m_pPickerView.frame=CGRectMake(20, 60, 240, 150);

         m_pPickerView.delegate=self;

         [alertView addSubview:m_pPickerView];

        

         self.AlertName=@"增加名片";


相关文章推荐

【IOS】自定义UIAlertView样式,实现可替换背景和按钮

【原创作品, 欢迎转载,转载请在明显处注明! 谢谢。         原文地址:http://blog.csdn.net/toss156/article/details/7552075】 ...

二十三 ,iOS UIAlertView使用block来实现代理方法;

在项目开发中很多时候都会用到只需要弹出一个信息提示框,用户只需要按确定即可,有时候处理事件,有时候不处理事件;利用block对此方法进行封装,还是利用UIalertView,用的时候考虑下(UIAle...

自定义UIAlertView样式,实现可替换背景和按钮

原文地址:http://blog.csdn.net/toss156/article/details/7552075】           UIAlertView 是一个十分常用的控件,网上也有...

Android 自定义Dialog 实现类似ios7 UIAlertView

效果图 实现步骤 1.AlertDialog.java /** * * @author zhangwen 2014-12-22 * 只带有一个确认按钮的dialog * */ ...

模仿系统方法自定义UIAlertView的实现和代理

背景是博主偷懒依然用了iOS8后被废弃掉的UIAlertView,然后取消的字体比确定要粗,同时为了统一界面风格,需要把UIAlertView统一换成定制的样子,博主就犯难了,又不想大批量更改代码,怎...

【IOS】自定义UIAlertView样式,实现可替换背景和按钮

【原创作品, 欢迎转载,转载请在明显处注明! 谢谢。         原文地址:http://blog.csdn.net/toss156/article/details/7552075】 ...

自定义UIAlertView样式,实现可替换背景和按钮

UIAlertView 是一个十分常用的控件,网上也有好多类似的自定义AlertView的方法。但是感觉效果都不是很好,它们有的是在系统自带的上面添加文本框,也有的是完全自己用UIView来实现,还有...

【IOS】自定义UIAlertView样式,实现可替换背景和按钮

UIAlertView 是一个十分常用的控件,网上也有好多类似的自定义AlertView的方法。但是感觉效果都不是很好,它们有的是在系统自带的上面添加文本框,也有的是完全自己用UIView来实现,还有...

自定义UIAlertView样式,实现可替换背景和按钮

原文地址:http://blog.csdn.net/toss156/article/details/7552075  UIAlertView 是一个十分常用的控件,网上也有好多类似的...

iOS 实现类似UIAlertView 和UIAlertController弹窗动画效果

UIAlertView和UIAlertController 项目中使用的很频繁的,但是系统的样式很多时候满足不了我们的需求,这时候我们需要自定义AlertView,但是我们又想做到像系统那样的动画效果...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)