• iOS开发笔记


    1、可以根据类的成员变量名称来读取内容,类的成员变量的值
    定义一个:Person类
    @interface Person : NSObject
    @property(nonatomic,strong)NSString *name;
    @property(nonatomic)NSUInteger age;
    @property(nonatomic,strong)NSString *aderss;
    +(NSArray *)demoData;//demoData:返回一个数组,数组里包含了N个Person实例对象
    @end
     
    NSArray *pps=[Person demoData];//获取Person数据
    NSLog(@"%@",[pps description]);//输出,输出结果是Person对象的地址(没有输出对象成员变量的值)
    NSArray *str=[pps valueForKey:@"name];//通过关键字name读取,所有对象的name的值
    NSLog(@"%@",[str description]);
     
    2、代码设置TableViewCell的行高
    注册Cell:
    [self.tableView registerClass:[UITableViewCell classforCellReuseIdentifier:MYCELL];
    //第三问
    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
        TRMessageCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyCell"];
    //注意不能有forIndexPath:indexPath,不然会报错
    //cell=[tableView dequeueReusableCellWithIdentifier:@"MyCell" forIndexPath:indexPath];
        cell.message self.allMessages[indexPath.row];
        return cell;
    }
    //设定每行的行高
    -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
        //找到indexPath对应的cell,返回cellbounds中的height
        UITableViewCell *cell = [self tableView:tableView cellForRowAtIndexPath:indexPath];
        return cell.bounds.size.height;
    }
     
    3、判断数组是否存在某对象
    - (BOOL)containsObject:(id)anObject
    如:
    BOOL flage=[@[@"gugu",@"kuku",@"huihui",@"meimei"containsObject:@"xxxx"];
     
    4、NSNotificationCenter:通知事件类型汇总
    格式:UI . . . Notification
    1)关于应用程序的通知:以UIApplication开头,以Notification结束,结构:UIApplication . . . Notification
    a、UIApplicationWillResignActiveNotification:应用程序将要进入后台
     
    2)键盘的通知: UIKeyboard . . . Notification
    a、UIKeyboardDidShowNotification:键盘已经显示
     
    时间:2015年07月06日
    1、将NSString转换成C语言类型的简单方法:
    NSString *str=@“abcdef”;
    const char *aa=str.UTF8String;//这个方法是转换成const char *类型的
     
    2、**:双指针,一般是用来取回值。
     
    时间:2015年07月07日(晚
    1、今晚发现的,今天在写一个数据库操作的程序,发现拖到项目里的数据库在编译的没有copy到APP的目录下(NSBundle)。
     
    时间:2015年07月08日(上午
    1、延时:
    [NSThread sleepForTimeInterval:1];//线程延时1秒
    2、获取当前的线程(通用)
    [NSThread currentThread];
     
    时间:2015年07月14日(下午
    1、版本号:
    NS_CLASS_AVAILABLE(NSURLSESSION_AVAILABLE7_0:  //7.0的版本
    #define NSURLSESSION_AVAILABLE 10_10://10_10:这表示10.10的版本
     
     
    时间:2015年07月21日(上午
    1、从路径中获取文件名称
    NSString *name=[iconString lastPathComponent];//Component:组成、部分
    NSLog(@"filePath:%@",name);
    输出结果:wsymbol_0006_mist.png
     
    2、对字典的操作:读、写
    直接使用[],而不是使用xxx方法
    self.images[iconSting]=image;//写入一条数据:iconSting是key,image是值
    UIImage *image=self.images[gaWeather.iconURLStr];//读取
     
    时间:2015年07月22日(上午
    1、使用字典快速给对象赋值
    一个对象:
    @interface GADeal : NSObject
     
    @property(nonatomic,strong)NSString *title;
    @property(nonatomic,strong)NSString *detail;
     
    @end
    //dic是一个字典,
    GADeal *gaDeal=[[GADeal alloc]init];
    [gaDeal setValuesForKeysWithDictionary:dic];//通过字典的key对应gaDeal对象的成员变量,会自动匹配,并赋值
     
    //注意:
    1、类成员变量名称要和字典的key相同,不然查找不到
    2、类的成员变量个数要小于字典key的个数
    3、如果字典的key名称(如关键字)和类的成员变量(不可能是关键字)冲突, 就必须重写- (void)setValue:(id)value forUndefinedKey:(NSString *)key方法
     
    2、可变的类一定要初始化。
     
    时间:2015年07月24日(下午
     1、暂停:
         sleep(2);
     
    时间:2015年07月27日(上午
    1、监听:KVC模型
        /*
         *  mainView添加一个观察者,mainView是一个UIView类型
         *  KeyPath:监听frame这个属性,只能监听对象的属性
         *  options:监听新值的改变
         */
        [mainView addObserver:self forKeyPath:@"frame" options:NSKeyValueObservingOptionNew context:nil];
    // 重写这个方法,当_mainViewframe属性改变的时候就会调用
    - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
    {
        NSLog(@"%@"NSStringFromCGRect(mainView.frame));
    // 添加代码
    }
     
    2、查询执行了哪个方法(函数)
    NSLog(@"%s", __func__);//用来查询当前执行的方法,写在哪,就会输出哪个方法/函数的名称
     
    3、获取设备信息
    //获取系统版本号
    double vertion=[[UIDevice currentDevice].systemVersion doubleValue];
     
     
    1、循环遍历数组
    定义一个成员变量self.currentIndex
    self.currentIndex++;//成员变量自+1
    //成员变量取余数组个数,返回的就是0 — self.fileNames.count - 1的值。
    self.currentIndex %= self.fileNames.count;
     
    不使用第三方的参数,实现两个数的交换
    方式一、
    func swap(inout num1:Int,inout num2:Int){
        num1 = num1 + num2
        num2 = num1 - num2
        num1 = num1 - num2
    }
    方式二、异或
    func swap(inout num1:Int,inout num2:Int){
        num1 = num1 ^ num2
        num2 = num1 ^ num2
        num1 = num1 ^ num2
    }

     define文件

    1、只是文本替换:
    //通知中心
    #define GANotificationCenter [NSNotificationCenter defaultCenter]
     
    2、带参数替换,在括号内的就是参数,没有数据类型。
    #define GAString(str) [ NSString stringWithFormat:@" %@ ",str]
     
     
     
    使用工具: Cornerstone
    1、svn的项目管理
    最重要的是那个隐藏的文件:.svn文件夹,只要有这个文件夹,只要相同的项目,都可以进行替换。在这个文件中存储了所有对项目的信息、内容和操作的数据。
     
    .svn文件夹的位置不能动,移动到别的地方,Cornerstone搜索不到就会报错。但我们可以移动其他文件。因为Cornerstone是根据.svn文件夹中存储的数据来检索项目的。
     
    使用cornerstone遇到的问题:
    使用cocopods的管理第三方库,有的文件(特别注意 * .a文件)没有上传到服务器,导致别人checkout后,就没有文件导致xcode报错。
     
    进一步分析:在本地的项目没有问题,上传cornerstone后再checkout后就出错的根本原因就是:cornerstone的设置问题
     
     
     
     
     
     
     
     
  • 相关阅读:
    override 和 重载的区别? Kevin
    EntityFramework SaveChange()方法不能更新的问题 Kevin
    Visual Studio 2010中找不到 entity framework模版 Kevin
    在数据库发生更改时更新 .edmx 文件(MSDN) Kevin
    MVC 3 RoutingSystem Kevin
    用递归的方法计算第30位斐波那契数列的值 Kevin
    log4net的日志输出格式log4net.Layout.PatternLayout用法 Kevin
    JavaScript: The Definitive Guide, 6th Edition Chapter 1 Note 1 Kevin
    闲谈生意人、商人和企业家的区别
    stlport 5.10 编译 更加容易了(visual studio 2005)
  • 原文地址:https://www.cnblogs.com/lignpeng/p/5458382.html
Copyright © 2020-2023  润新知