现在的位置: 首页 > 综合 > 正文

随手记

2018年01月16日 ⁄ 综合 ⁄ 共 2688字 ⁄ 字号 评论关闭
</pre><span style="color:rgb(51,51,51); font-family:Verdana,sans-serif,宋体; font-size:13px; letter-spacing:0.5px; line-height:22.5px"></span><p></p><pre code_snippet_id="615143" snippet_file_name="blog_20150313_1_9837556" name="code" class="objc"></pre>一、[[UIScreen mainScreen]bounds]与[[UIScreen mainScreen]applicationFrame的区别<p></p><p><span style="color:rgb(51,51,51); font-family:Verdana,sans-serif,宋体; font-size:13px; letter-spacing:0.5px; line-height:22.5px">bounds就是屏幕的全部区域,applicationFrame就是app显示的区域,不包含状态栏(高度20,如果状态栏隐藏的话,那么,这个结果就和bounds一样了</span></p><p><span style="font-family:Verdana,sans-serif,宋体; font-size:12px; color:#333333"><span style="letter-spacing:0.5px; line-height:22.5px">二、一边遍历数组,一边修改数组中的数据</span></span><span style="color:rgb(51,51,51); font-family:Verdana,sans-serif,宋体; font-size:13px; letter-spacing:0.5px; line-height:22.5px"></span></p><pre code_snippet_id="615143" snippet_file_name="blog_20150309_1_840859" name="code" class="objc">- (BOOL)isExistWithIndexPath:(NSIndexPath *)indexPath
{  
    BOOL isExist = NO;
    Sport * sport = self.sportListArray[indexPath.row];
    NSMutableArray * tempArray = [NSMutableArray arrayWithArray:self.sportNameArray];
    
    for (NSString * name  in tempArray) {
        if ([name isEqualToString:sport.sportName]) {
            isExist = YES;
            [self.sportNameArray removeObject:name];
        }
    }
    
    return isExist;
}

三、判断字符串是否为空宏

#define IsEmptyString(str) (([str isKindOfClass:[NSNull class]] || str == nil || [str length]<=0)? YES : NO )

四、程序的推出与恢复

//在应用退出时调用,负责控制是否允许保存状态,返回YES情况可以保存,NO是不保存
-(BOOL)application:(UIApplication*)application shouldSaveApplicationState:(NSCoder *)coder{
    return YES;
}
//在应用启动时调用,负责控制是否恢复上次退出似的状态,返回YES可以恢复,NO不可以恢复
-(BOOL)application:(UIApplication *)application shouldRestoreApplicationState:(NSCoder *)coder{
    return YES;
}
//方法在保存时调用,在这个方法中实现UI状态保存或保存数据,其中[coder encodeFloat:2.0 forKey:@"Version"];语句时保存简单数据
-(void)application:(UIApplication *)application willEncodeRestorableStateWithCoder:(NSCoder *)coder{
    [coder encodeFloat:2.0 forKey:@"Version"];
}
//方法在恢复时调用,在这个方法中实现UI状态恢复或恢复数据,其中[coder encodeFloat:2.0 forKey:@"Version"];语句是读取上次保存的数据
-(void)application:(UIApplication *)application didDecodeRestorableStateWithCoder:(NSCoder *)coder{
    float lastVer = [coder decodeFloatForKey:@"Version"];
    NSLog(@"lastVer = %f",lastVer);
}

五、对数组内的元素进行排序

NSMutableArray *array = [[[NSMutableArray alloc] initWithObjects:@"1", @"2", @"3", nil] autorelease];

array = (NSMutableArray *)[[array reverseObjectEnumerator] allObjects];

六、viewController中加载单独的xib
    NSArray *nibContents = [[NSBundle mainBundle] loadNibNamed:@"SetViewOfLogin"
                                                         owner:nil
                                                       options:nil];
    UIView * viewcc = (UIView*)[nibContents objectAtIndex:0];
    viewcc.frame = CGRectMake(0, 0, 320, 300);
    [self.view addSubview:viewcc];

七、iOS 8 新修改的定位方式选择
实现方法:在plist文件中添加NSLocationAlwaysUsageDescription   始终允许程序获取GPS信息  和   NSLocationWhenInUseUsageDescription   使用期间允许获取GPS信息

抱歉!评论已关闭.