• IOS工作笔记(八)


    说明:记录下学习IOS的一些琐碎,有些在现在看起来很简单幼稚,不过权当学习足迹吧!

    1.如何删除UIScrollView下的所有子视图?

    对于一般的UIView,可以用

    for (UIView *view in myView) {
        [view removeFromSuperview];
    }

    但对于UIScrollView,会有警告
    Collection expression type 'UIScrollView *' may not respond to 'countByEnumeratingWithState:objects:count:'
    此时需要用另一种方法

    UIScrollView *myScrollView = [[UIScrollView alloc]init];
    if (myScrollView.subviews.count) {
        [myScrollView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    }

    简单粗暴。并且该方法适用于所有的UIView

    2.iphone点击return如何隐藏键盘?

    首先,得实现UITextField的代理
    在.h中

    @interface ZMLoginViewController : UIViewController<UITextFieldDelegate>

    在.m中

    - (void)viewDidLoad {
        [super viewDidLoad];
        //将textField的代理设为controller
        self.accountField.delegate = self;
        self.pwdField.delegate = self;
    }

    实现下述方法即可

    -(BOOL)textFieldShouldReturn:(UITextField *)textField{
        [textField resignFirstResponder];
        return YES;
    }

    3.UIViewController有title的属性,可以设置标题。但前提是要先设置了UINavigationController,title才有意义。

    如在AppDelegate中设置

    SlideToSwitchController *myController2 = [[SlideToSwitchController alloc]init];
    UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:myController2];
    self.window.rootViewController = nav;

    然后在SlideToSwitchController的.m中

    self.title = @"切换视图";

    才会显示标题。如图:

    4.使用aftnetworking从后台获取json时,有时会出现直接跳到failure的情况,这时可能的原因有后台的json格式不准确,所以就不能执行,这是花了一下午的教训。接受的数据类型还得跟后台多沟通,有时需多加几种。如:

    requestManager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/plain", @"text/html", nil];
    //@"text/plain"和@"text/html"的区别在于plain是文本形式,html为网页形式

    5.当UItableView只有1个section,而数据源dataSource又有多种时,可以考虑如下处理:

    既然不同数据源的数据可以放到同一tableview展示,说明其格式相同,这时可以再定义一个新的统一的model,相当于把不同数据源的model格式化,然后就可以处理。
    该方法是目前所能想到的最简单方法。

    6.自定义cell,里边有button,label等时,点击button获取cell所在的位置(位于tableview的哪个section,哪一列),可以用这个

    NSIndexPath *indexPath = [(UITableView *)self.superview.superview indexPathForCell:self];
    //self指UITableViewCell

    7.textfield用代码定义时,默认是没有边框的,若想有边框,还需再加

    self.accountField.borderStyle = UITextBorderStyleRoundedRect;
  • 相关阅读:
    redis在linux下的安装
    Redis在系统中的使用
    使用ServiceStackRedis操作redis
    Redis命令
    mongo增删改操作
    mongo c#驱动介绍操作
    LeetCode 19 删除链表的倒数第N个节点
    LeetCode 01 两数之和
    metapath2vec 笔记
    Q&A(一)
  • 原文地址:https://www.cnblogs.com/Apologize/p/4332519.html
Copyright © 2020-2023  润新知