zoukankan      html  css  js  c++  java
  • ios 入门笔记(引起用户注意)


    alertDialog

    要将相应创建的类的接口中遵守协议

    @interface ViewController : UIViewController <UIAlertViewDelegate, UIActionSheetDelegate>   //此处是UIAlertViewDelegate

    初始化实现:- (IBAction)doMultiButtonAlert:(id)sender {
        UIAlertView *alertDialog;                  //触发了该操作后,创建一个ALERTVIEW,
        alertDialog = [[UIAlertView alloc]
                       initWithTitle: @"Alert Button Selected"       //提醒的标题
                       message:@"I need your attention NOW!"   //提醒的内容
                       delegate: self                  //如果委托刚好是创建提醒视图对象,则SELF,(通常是VIEWCONTROL 遵循协议)
                       cancelButtonTitle: @"Ok"
                       otherButtonTitles: @"Maybe Later", @"Never", nil];   //以NIL结尾,表示多个提醒按钮

          alertDialog.alertViewStyle=UIAlertViewStylePlainTextInput;       //加这一行就变成了有一个文本框 如果是UIALERTVIEWSECURETEXTINPUT密码文本框UIALERTVIEWSTYLELOGINANDPASSWORDINPUT一个普通文本框,一个密码文本框。


        [alertDialog show];                 //出现视图
    }

    如要对提醒中按中什么按钮执行相应操作

    - (void)alertView:(UIAlertView *)alertView                     //传入进去的是按下按钮的索引buttonindex就是按下按钮的索引,写作遵循协议类的实现中,该方法必须要写是协议
            clickedButtonAtIndex:(NSInteger)buttonIndex {                    
        NSString *buttonTitle=[alertView buttonTitleAtIndex:buttonIndex];    //bottonTitleAtindex:buttonIndex返回按下按钮的标题
        if ([buttonTitle isEqualToString:@"Maybe Later"]) {
            self.userOutput.text=@"Clicked 'Maybe Later'";
        } else if ([buttonTitle isEqualToString:@"Never"]) {
            self.userOutput.text=@"Clicked 'Never'";
        } else {
            self.userOutput.text=@"Clicked 'Ok'";
        }
        
        if ([alertView.title
             isEqualToString: @"Email Address"]) {
            self.userOutput.text=[[alertView textFieldAtIndex:0] text];
        }
    }

    获取提醒中文本框内容

    if ([alertView.title
             isEqualToString: @"Email Address"]) {
            self.userOutput.text=[[alertView textFieldAtIndex:0] text];     //alertView textFieldAtIndex:0  //若只有一个文本框,则选中了那个文本框,发送消息text,则获得了用户输入的内容
        }


    ActionSheet

    要将相应创建的类的接口中遵守协议

    @interface ViewController : UIViewController <UIAlertViewDelegate, UIActionSheetDelegate>   //此处是UIActionSheetDelegate

    创建方法

    - (IBAction)doActionSheet:(id)sender {
        UIActionSheet *actionSheet;                //触发相应操作后,执行actionSheet
        actionSheet=[[UIActionSheet alloc] initWithTitle:@"Available Actions"   //标题题目
                                      delegate:self
                             cancelButtonTitle:@"Cancel"          //指定操作表默认按钮标题
                        destructiveButtonTitle:@"Destroy"        //会以醒目红色提示,指定将导致信息丢失的按钮标题,如果NIL则不显示此按钮
                             otherButtonTitles:@"Negotiate",@"Compromise",nil];
        actionSheet.actionSheetStyle=UIActionSheetStyleBlackTranslucent;       //半透明样式
        [actionSheet showFromRect:[(UIButton *)sender frame]     //这一段是针对IPAD的
                           inView:self.view animated:YES];
    //    [actionSheet showInView:self.view];
    }

    响应操作表

    - (void)actionSheet:(UIActionSheet *)actionSheet            //传入按了按钮的索引
            clickedButtonAtIndex:(NSInteger)buttonIndex {
        NSString *buttonTitle=[actionSheet buttonTitleAtIndex:buttonIndex];
        if ([buttonTitle isEqualToString:@"Destroy"]) {
            self.userOutput.text=@"Clicked 'Destroy'";
        } else if ([buttonTitle isEqualToString:@"Negotiate"]) {
            self.userOutput.text=@"Clicked 'Negotiate'";
        } else if ([buttonTitle isEqualToString:@"Compromise"]) {
            self.userOutput.text=@"Clicked 'Compromise'";
        } else {
            self.userOutput.text=@"Clicked 'Cancel'";
        }
    }


    实现声音,震动

    需要导入

    #import <AudioToolbox/AudioToolbox.h>

    实现

    - (IBAction)doSound:(id)sender {
        SystemSoundID soundID;             //创建变量soundID它指向声音文件
        NSString *soundFile = [[NSBundle mainBundle]    //字符串变量soundFile  设置为soundeffect.wav的路径
                               pathForResource:@"soundeffect" ofType:@"wav"];
        
        AudioServicesCreateSystemSoundID((__bridge CFURLRef)             //使用函数创建SystemSoundID(表示文件soundeffext.wav)供播放声音函数使用
                                         [NSURL fileURLWithPath:soundFile]
                                         , &soundID);
        AudioServicesPlaySystemSound(soundID);          //使用函数AudioServicesPlaySystemSound播放声音
    }

    震动

    实现

    - (IBAction)doVibration:(id)sender {
        AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);     //只需要在播放声音的函数中使用变量kSystemSoundID_Vibrate就可播放震动
    }

  • 相关阅读:
    C语言读写伯克利DB 4
    程序之美(转自知乎)
    C语言读写伯克利DB 3
    ON DUPLICATE KEY UPDATE
    nanomsg:ZeroMQ作者用C语言新写的消息队列库
    新浪研发中心: Berkeley DB 使用经验总结
    [企业开源系列]后起之秀Facebook凭什么挑战互联网霸主Google?
    BZOJ1770:[USACO]lights 燈(高斯消元,DFS)
    BZOJ5293:[BJOI2018]求和(LCA,差分)
    BZOJ5301:[CQOI2018]异或序列(莫队)
  • 原文地址:https://www.cnblogs.com/Ponytai1/p/6083251.html
Copyright © 2011-2022 走看看