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

    一些开发中的常见问题:

    1、interface builder 使用

    identity inspector 的key path 可以用来做圆角按钮和边框,不用在代码里面写。

     layer.cornerRadius number  圆角按钮

    2、内存管理
    使用代理模式的时候,A 和 B的相互引用之间会循环引用,导致内存无法回收。 解决方案:可以使其中一个引用设置为weak。
    需要注意的是,如果是A持有B,那么A的生命周期比B长,应该把B持有A的引用设置成weak。
     
     
     
    3、导航栏颜色 
    navigationBar 默认是透明的,颜色会进行高斯模糊处理。所以直接用RGB颜色赋值,最后的颜色效果会稍微淡一些。
    解决方案:最开始的navigationBar设置为opaque。
     
     
     4、HTTP请求
    如果是post请求,并且设置了 httpBody,那么请求的超时时间就被默认设置为 240 秒了。
    就算你再使用[urlRequest setTimeoutInterval:10]; 也是无效的,我们可以再设置完成后再读取这个值,发现它不会变成10,依然保持240秒。
    以上是开发中遇到的问题,在iOS9以后,问题都不在了:

        AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];

        manager.requestSerializer.timeoutInterval = 10;

    这个方法亲测有效。(AFNetworking) 
     
     
    5、UIViewcontroller 层级
    presentViewController 和  UINavigationController的区别:
     
    presentViewController 一般用于一个viewcontroller
     
    同时,dismiss会让所有的presents的view全部消失。(go back,不方便)

    UINavigationController 更灵活,可以push,然后pop。
    (更新:iOS9中,是可以在modal的viewController中,再modal一次的viewController的)
     
     
    6、UITableViewCell 自适应
    cell.contentView.systemLayoutSizeFittingSize(UILayoutFittingCompressedSize).height + 1 
    这个方法可以在对cell进行初始化后,对cell的高度进行预先处理。
     
     
    7、多线程
    其他线程如何操作(更新)UI。

    [self performSelectorOnMainThread:@selector(updateUI:) withObject:image waitUntilDone:YES];

    performSelectorOnMainThread是NSObject的方法,除了可以更新主线程的数据外,还可以更新其他线程的比如: 
    用:performSelector:onThread:withObject:waitUntilDone: 
     
     

    8、UI自动布局

    layout有三种方式:Manual layout,Autoresizing,Autolayout。我们常用的可能就后面两种。

    假设v1是一个不使用autolayout的view,而v2是一个使用autolayout的view,但v1成为v2的subview时,

    v2需要四条隐含的constraint来确定v1的位置,这些约束都是从v1的frame转化而来:

    This conversion is performed only if the view in question has its translates-

    AutoresizingMaskIntoConstraints property set to YES. That is, in fact, the default if

    the view came into existence either in code or by instantiation from a nib where “Use

    Auto Layout” is not checked. The assumption is that if a view came into existence in

    either of those ways, you want its frame and autoresizingMask to act as its constraints

     
    if it becomes involved in autolayout. 
     
     
     
     
     
     
     9、UI数据传递
    能不能在destination controller 中调用prepareForSegue 来回传数据?
    不能。
    因为:prepareForSegue只有当将一个controller放到堆栈上面的时候可以使用,如果将一个controller从堆栈上面移除,是无法使用的,具有单向性。
     
    self.navigationController popToRootViewControllerAnimated:YES]
     
     
    UIViewController *prevVC = [self.navigationController.viewControllers objectAtIndex:<n>];
    [self.navigationController popToViewController:prevVC animated:YES];
    
    

    [self.navigationController popViewControllerAnimated:YES];

     (那么可以通过单例、代理模式、notify等各种形式传递)

    10、UIViewoController的关系

    移出孩子的操作
    If you are implementing your own container view controller, it must call the willMoveToParentViewController: method of the child view controller before calling the removeFromParentViewController method...

    Thus, as discussed in Adding and Removing a Child section of the View Controller Programming Guide, when removing a child, we should:


    [childVC willMoveToParentViewController:nil];
    [childVC.view removeFromSuperview];
    [childVC removeFromParentViewController];
     
  • 相关阅读:
    JNDI----数据连接池
    转发和重定向的区别
    vs编译程序不能实现,“未能完成操作 未指定的错误”的解决办法
    error C1853: “DebugBigBuffer.pch”预编译头文件来自编译器的早期版本,或者预编译头为 C++ 而在 C 中使用它(或相反)
    monkey测试结果分析
    VSpy之C Code Interface的使用
    C++常备知识总结
    关于“调试会话的可执行文件”对话框
    The JVM found at JAVA_HOME is damaged.Please reinstall or define EXE4J_JAVA_HOME to point to an installed 32-bit JDK or JRE
    exe4j中"this executable was created with an evaluation version of exe4j"
  • 原文地址:https://www.cnblogs.com/loying/p/4811356.html
Copyright © 2011-2022 走看看