zoukankan      html  css  js  c++  java
  • 小知识点总结

    小知识点总结

     

    1、从服务器返回一个data类型的图片数据:

    // 图片地址

    NSURL* url = [NSURL URLWithString:@"http://www.baidu.com/img/baidu_sylogo1.gif"];

    // 请求图片

        NSData* data = [NSData dataWithContentsOfURL:url];

        UIImage* image = [UIImage imageWithData:data];

    // 去主线程刷新UI

       self.imageView.image = image;

    2、

    <root xmlns:book="http://www.baidu.com" xmlns="http://www.sina.com.cn" id="1"/>

    //添加命名空间

        GDataXMLElement* ele = [GDataXMLElement elementWithName:@"root"];

        [ele addNamespace:[GDataXMLElement namespaceWithName:@"book" stringValue:@"http://www.baidu.com"]];

        //添加缺省命名空间

        [ele addNamespace:[GDataXMLElement namespaceWithName:@"" stringValue:@"http://www.sina.com.cn"]];

        //添加属性值

        [ele addAttribute:[GDataXMLElement attributeWithName:@"id" stringValue:@"1"]];

    3、判断是否为iphone5

    CGFloat screenWidth = [[UIScreen mainScreen] bounds].size.width;

            CGFloat screenHeight = [[UIScreen mainScreen] bounds].size.height;

            if ((screenWidth==568)||(screenHeight==568)) {

                isiPhone5 = YES;

            }

    4.iphone5宽高:320*568

      CGFloat screenWidth = [[UIScreen mainScreen] bounds].size.width;

     CGFloat screenHeight = [[UIScreen mainScreen] bounds].size.height;

    5、打开系统小转圈

        [UIApplication sharedApplication].networkActivityIndicatorVisible=YES;

       关闭小转圈

    [UIApplication sharedApplication].networkActivityIndicatorVisible=NO;

    6、使得view可交互:

    UIImageView* _imageView;

    _imageView.userInteractionEnabled = YES;

    7、沙盒路径:

    方法一:

      NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

             NSString *documentsDirectory = [paths objectAtIndex:0];

           NSString *imgPath = [documentsDirectory  stringByAppendingPathComponent:@"loading.plist"];

    方法二:

           NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/loading.plist"];

    相对而言第二种方法比较简单 做了很久才理解这两种方法的区别

    第一种方法可以直接获取到沙盒下Documents路径即AtIndex 0 取出的就是Documents的路径

    第二种方法就是直接取出沙盒下的所有目录:Documents,temp,app,libiary 

    如果用第二种方法读取文件路径的时候,要把该文件对应的前一个目录写出来,想要写入到沙盒的时候也要加上前一个目录的路径,如果用第一种方法就可以不加前一个目录的路径

    8、选择相册图片

    //选择图片

        UIImagePickerController* ipc = [[UIImagePickerController alloc] init];

        ipc.delegate = self;

        //来源

        ipc.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

        [self presentViewController:ipc animated:YES completion:nil];

        [ipc release];

    代理:

    //点击图片调用

    - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{

        _imageView.image = [info objectForKey:UIImagePickerControllerOriginalImage];

        [picker dismissViewControllerAnimated:YES completion:nil];

    }

    //点击取消按钮调用

    - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{

        [picker dismissViewControllerAnimated:YES completion:nil];

    }

    9、把图片转为NSData格式:

    NSData* data = UIImagePNGRepresentation(_imageView.image);

    10、把自定义的按钮显示到导航栏上

    UIButton *button=[UIButton buttonWithType:UIButtonTypeRoundedRect];

        button.frame=CGRectMake(0, 0, 40, 30);

        [button setTitle:@"push" forState:UIControlStateNormal];

        [button addTarget:self action:@selector(btnDown) forControlEvents:UIControlEventTouchUpInside];

        self.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc] initWithCustomView:button];

    11、如果在B页面修改了数据影响到A页面,并要立马在A页面体现出来,则应该:

    -(void)viewWillAppear:(BOOL)animated

    {

            // 一进入这个VC立马刷新数据,使得数据立马能展现到cell上,

        [_tableView reloadData];

    }

    12、为自定义按钮等自定义空间添加监听的时候,用到控制器的方法时候:应该先拿到控制器

    // presentViewController方法是控制器的方法,如果是自定义的一些空间的话,首先需要拿到控制器,才能使用这个方法。

        // 因为控制器展示在跟视图控制器上,因此我们只需要拿到跟视图控制器self.window.rootViewController

        [self.window.rootViewController presentViewController:nav animated:YES completion:nil];

    13、用pinyin4objc框架可以对拼音进行排序,例如把城市按字母排序

    14、UIPopoverController

    UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:city];

        // inView:是谁,小箭头则指向谁

        // 这里属性有两种传法:1、self.bounds--self 2、self.frame--self.superview

        [popover presentPopoverFromRect:self.bounds inView:self  permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

        _popover = popover;

    注意:popover的箭头指向PopoverFromRect:self.bounds,必须要告诉self.bounds是 指的是谁,这里是self;或者是self.frame--self.superview,即:在父视图是 self.superview上得子视图位置为self.frame处显示小箭头

    15、在searchBar上显示取消按钮

        [searchBar setShowsCancelButton:YES animated:YES];

    16、隐藏键盘:

    [_searchBar endEditing:YES];

        [_searchBar resignFirstResponder];

    17、CocoaPods安装和使用教程(类库管理工具

    http://code4app.com/article/cocoapods-install-usage 

    18、在点击table上的cell后返回的时候设置颜色不反选:(在cell选中代理中设置)

    [tableView deselectRowAtIndexPath:indexPath animated:YES];

    19、从相机、相册等选择图片

        UIImagePickerController* ipc = [[UIImagePickerController alloc] init];

        ipc.delegate = self;

        //来源

        ipc.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

        [self presentViewController:ipc animated:YES completion:nil];

    20、让UIscrollView只能实现左右滑动,不能上下滑动,把内容高度设置为0即可

    self.scrollView.contentSize = CGSizeMake((kScreenH-40)*(pageCount-1),0); //(kScreenH-40)

    21、

    NSString *URLTmp = @”http://www.coneboy.com”;

    NSString *URLTmp1 = [URLTmp  stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];  //转码成UTF-8  否则可能会出现错误
    22、

     UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapDown:)];

        [self.imageViews addGestureRecognizer:tap];

        tags = imageViewTag;

    - (void) tapDown:(UITapGestureRecognizer *) tap

    {

        tags = tap.view.tag;// 点击不同图片,获取不同图片的tag值。

        ProductDetailViewController *product = [[ProductDetailViewController alloc] init];

        product.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;

        product.picStr = tags;

        [self presentViewController:product animated:YES completion:nil];

    }

    23、本地化:

    “项目(蓝色 图标)”—》“info”—》Locations—》“+” chinese

    24、数据转化为模型的方法:

      NSDictionary *dict = _citysData[0];

        1、把数据转化为模型(方法一)

        CitySection *section = [[CitySection alloc] init];

        section.name = dict[@"name"]; // 最复杂的转化为模型的方法

        section.cities = dict[@"citys”];

    2、  把数据转化为模型(方法二) KVC(效率低)

        // 会取出dict中得每个key付给我们的section对象

        // 即:先取出secton中得name属性,并赋值为dict中得name属性的值,再

        // section中有name,citys属性

        [section setValuesForKeysWithDictionary:dict];// 等同于与下面两句

        [section setValue:dict[@"name"] forKey:@"name"];

        [section setValue:dict[@"cities"] forKey:@"cities"];

    3、#import <objc/message.h>

    25、 把首字母大写

        NSString *first = [key subStringToIndex:1].uppercaseString;

    26、self.automaticallyAdjustsScrollViewInsets 

    这个属性是IOS7才有的新方法,目的就是为了让scrollView自动适应屏幕,

    如果self.automaticallyAdjustsScro   llViewInsets = NO,那么效果会变成下图所示: 

      
     
    27、cell选中,再返回时候cell不再显示灰色
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    28、图片圆角设置
    self.asyImage.layer.cornerRadius = 8;

        self.asyImage.layer.masksToBounds = YES;

    29、边框宽度及颜色设置     

        [imageView.layer setBorderWidth:2];

        [imageView.layer setBorderColor:[UIColor blueColor]];  //设置边框为蓝色

    30、自动适应,保持图片宽高比

        imageView.contentMode= UIViewContentModeScaleAspectFit;

    31、在别的方法中获取cell

            NSIndexPath *index = [NSIndexPath indexPathForRow:i inSection:0];

            UITableViewCell *cell = (UITableViewCell *)[tableView cellForRowAtIndexPath:index];

    32、活动指示器

    [[AFNetworkActivityIndicatorManager sharedManager] setEnabled:YES];

    33、便利字典cities (字典中得每一个block都会调用这一个block)

        [cities enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { 

        }];

    34、把小写变为大写(忽略大小写就是这么干的)

    searchText.uppercaseString

    35、字符串截取SHI#JIA#ZHUANG

            [pinyin componentsSeparatedByString:@"#”]; // 得到SHI ,JIA,ZHUANG数组

    36、 去掉pinyinHeader所有#(用@“123”替代@“#”)

            [pinyin stringByReplacingOccurrencesOfString:@"#" withString:@“123"];

    未完待续

  • 相关阅读:
    C#编程的最佳工具
    Visual Studio Code搭建python开发环境
    Python打包文件夹的方法小结(zip,tar,tar.gz等)
    【转】python文件和目录操作方法大全(含实例)
    win764位系统上让32位程序能申请到4GB内存方法
    [转]bigbluebutton中文社区 / 开放API / bbb API
    [转]26款 网络会议/视频会议开源软件
    【转】用python比对数据库表数据的脚本
    plsql查询数据库-中文显示问号问题
    plsql 使用desc命令提示invalid sql statement
  • 原文地址:https://www.cnblogs.com/huangh/p/4040210.html
Copyright © 2011-2022 走看看