zoukankan      html  css  js  c++  java
  • ios 开发小记 (三)

    iOS开发的常见问题:
     
    1、viewController的生命周期
    viewDidLoad
     viewDidUnload方法‍
    (loadView/nib文件)来加载view到内存 ——>viewDidLoad函数进一步初始化这些view ——>内存不足时,调用viewDidUnload函数释放views —->当需要使用view时有回到第一步,如此循环。
    - (void)viewDidLoad is not called when the view controller is loaded; it is called when the view controller's view is loaded.
     切记:viewDidUnload不是被移除的时候都会调用的函数。
     
     
     
     
     2、UIKit - UIButton
    操作button上的title,不要直接去操作label
    不应该button.titleLabel.text = @"test";
    这样越过了button的封装。
    应该使用 [button setTtile: forState:]的方法。
     
     
     3、JSON 数据转化
    NSJSONSerialization 可以用来转换json 和 object
     
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:object
                                                           options:NSJSONWritingPrettyPrinted // Pass 0 if you don't care about the readability of the generated string
                        error:&error];
    jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; 
    可以把一个dict To jsonstring
     
     
     NSDictionary* dict = [NSJSONSerialization JSONObjectWithData:[operation.responseString dataUsingEncoding:NSUTF8StringEncoding] options:0 error:nil];
    可以把一个json字符串 转为dict
     
     
     
     
    4、常用的ViewController的操作

      //根据 segue Identifier跳转界面

        [self performSegueWithIdentifier:@"GotoTwo" sender:self];

        

       //以modal 方式跳转

        [self presentModalViewController:nil animated:YES];

        

       //压进一个viewcontroller

        [self.navigationController pushViewController:nil animated:YES];

       //弹出一个viewcontroller  相当与返回上一个界面

        [self.navigationController popViewControllerAnimated:YES];

        

       // 以 modal跳转的返回方法

        [self dismissModalViewControllerAnimated:YES];

     
    Modal segues take over the whole screen, so any navigation bars, tool bars, or tab bars that are in the presenting controller will be covered up. If you want a navigation bar on this modal controller, you'll need to add one specifically to it, and add any buttons you want to that new navigation bar (or tool bar). If you don't want to do this, then don't present it modally, do a push to it.
    (这句话的翻译:modal 的ViewController是全屏的,没有navigationBar,如果需要,可以自己添加;或者用push不用modal) 
     
     
     
    5、storyboard的unwind segue
    - (IBAction)unwindSegueToIndexViewController:(UIStoryboardSegue *)segue {
    }
    exit 的连线 
    可以快速返回某一个ViewController。
     
     
     
     
    6、关闭APP之前,会调用的函数

    -(BOOL) application:(UIApplication *)application shouldSaveApplicationState:(NSCoder *)coder

    {
       
        return YES;
       
    }



    -(BOOL) application:(UIApplication *)application shouldRestoreApplicationState:(NSCoder *)coder
    {
        return YES;
    }



    - (void)application:(UIApplication *)application willEncodeRestorableStateWithCoder:(NSCoder *)coder
    {
       
        NSDate *date = [NSDate date];
        NSTimeInterval sec = [date timeIntervalSinceNow];
        NSDate *currentDate = [[NSDate alloc] initWithTimeIntervalSinceNow:sec];
       
        //设置时间输出格式:
        NSDateFormatter *df = [[NSDateFormatter alloc] init ];
        [df setDateFormat:@"yyyy年MM月dd日 HH小时mm分ss秒"];
        NSString *na = [df stringFromDate:currentDate];
       
       
        [coder encodeObject:na forKey:@"lastShutdownTime"];
       
    }



    - (void)application:(UIApplication *)application didDecodeRestorableStateWithCoder:(NSCoder *)coder

    {
       
       
        NSString * currentTime = [coder decodeObjectForKey:@"lastShutdownTime"];

        UIAlertView *alert = [[UIAlertView  alloc]
                              initWithTitle:@"上次关闭时间"
                              message:currentTime
                              delegate:nil
                              cancelButtonTitle:@"OK"
                              otherButtonTitles:nil];
        [alert show];
       
    }
     
     
    7、UI动画 

    下面是可以设置动画效果的属性:

    • frame
    • bounds
    • center
    • transform
    • alpha
    • backgroundColor
    • contentStretch
     
     
     8、UI事件
    不建议直接向nextResponder发送消息,这样可能会漏掉父类对这一事件的其他处理。
     
     
  • 相关阅读:
    Shell 批量搜索关键词并保存结果到文件中(数组、循环)
    解决tensorflow的Session Exception问题
    解决h5py的FutureWarning问题
    【转】Ubuntu16.04安装WPS
    [Linux] 随机切分文件内容
    [Python] 动态函数调用(通过函数名)
    [Python] dict字典的浅复制与深复制
    基于sklearn进行文本向量化
    Asp.Net MVC SingleServiceResolver类剖析
    Asp.Net MVC 高级特性(附带源码剖析)
  • 原文地址:https://www.cnblogs.com/loying/p/4811365.html
Copyright © 2011-2022 走看看