iOS_开发中遇到的那些问题_2

【自编号:286】【Cell点击特效 取消】
cell.selectionStyle = UITableViewCellSelectionStyleNone;  
【2015-04-23 17:23:15 by beyond】



【自编号:289】【隐藏导航条】
// 导航控制器的显示和隐藏【提示,如果使用navigationBarHidden属性,侧滑会出问题】
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = YES;
}
- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    self.navigationController.navigationBar.hidden = NO;
}
【2015-04-24 16:33:52 by beyond】



【自编号:291】【cell分割线设置,其实是tableView的属性separatorStyle】
将UITableView的separatorStyle属性设置为UITableViewCellSeparatorStyleNone即可,如下:
tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
【2015-04-28 14:08:31 by beyond】



【自编号:292】【cell图片在xib中aspect fit无效,只能用代码调整】
self.img.contentMode = UIViewContentModeScaleAspectFill;
self.img.clipsToBounds = YES;
【2015-04-30 15:49:49 by beyond】



【自编号:293】【代码改约束】
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        //        //    当事件触发时,改变其constant值,然后调用约束所在的对象的 layoutIfNeeded方法,固定的~ 例如:
        //        _topView.collectionViewHeightConstraint.constant = 50;
        //        //    self.leftMarginConstraint.constant = 100;
        //        //    self.widthConstraint.constant = 200;
        //        [UIView animateWithDuration:2.0 animations:^{
        //            [self.view layoutIfNeeded];
        //            [_topView layoutIfNeeded];
        //        }];
    });
【2015-05-04 14:57:22 by beyond】



【自编号:296】【appdelegate中的支付回调1】
// pay ---- 3
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
    [Pingpp handleOpenURL:url withCompletion:nil];
    [[NSNotificationCenter defaultCenter]postNotificationName:@"notificationCenter_userPayOrNot" object:nil];
    return  YES;

(lldb) po url
jzh://pingpp?result=success

(lldb) po sourceApplication
com.apple.mobilesafari

(lldb) po annotation
 nil
(lldb) 
}
【2015-05-05 11:31:40 by beyond】



【自编号:297】【OC的字典转成jsonString】
// 重要说明:content此时已经从json串 转成了OC的字典
        
        // 1种是 通过JSONKIT,可将字典转成json字符串;
        // self.jsonString = [(id)content JSONString];
        
        // 另1种是  通过NSJSONSerialization 转成Data,再从Data 转成jSON string
        NSData *data = [NSJSONSerialization dataWithJSONObject:content options:NSJSONWritingPrettyPrinted error:nil];
        self.jsonString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
【2015-05-05 17:06:12 by beyond】



【自编号:298】【二次包装过程】
将一个字典,包装成一个大的大典,再转成jsonString
// 二次包装过程
                                         NSArray *modelArr = [MarkModel objectArrayWithKeyValuesArray:dataArr];
                                         MarkBigModel *bigModel = [[MarkBigModel alloc]init];
                                         bigModel.FScore = 5;
                                         NSArray *dictArray = [MarkModel keyValuesArrayWithObjectArray:modelArr];
                                         
                                         bigModel.MciMcBusiSiteRemarkItems = dictArray;
                                         bigModel.RemarkCount = modelArr.count;
                                            // 模型 转 字典,之后就可以用字典 转 jsonString
                                         NSDictionary *bigDict = bigModel.keyValues;
                                         
                                         
                                         // 另1种是  通过NSJSONSerialization 转成Data,再从Data 转成jSON string,会有反斜线
                                         NSData *data = [NSJSONSerialization dataWithJSONObject:bigDict options:NSJSONReadingMutableLeaves error:nil];
                                         NSString *jsonString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
【2015-05-05 17:48:41 by beyond】



【自编号:299】【ineligible devices】
iphone 6 with 8.3系统,连接到xcode 6.01 时,
提示:ineligible devices
原因:xcode版本太低
解决办法:
换成xcode 6.1 即可
==============
 Xcode 6.1 update. The 6.0.1 does't support iOS 8.1.
【查看原文】 【2015-05-06 14:49:53 by beyond】



【自编号:301】【弹出动画】
注意在viewDidAppear调用
- (void)addKeyAnimation
{
    CAKeyframeAnimation * animation;
    animation = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
    animation.duration = 0.5;
    animation.delegate = self;
    animation.removedOnCompletion = YES;
    animation.fillMode = kCAFillModeForwards;
    
    NSMutableArray *values = [NSMutableArray array];
    [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.1, 0.1, 1.0)]];
    [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.2, 1.2, 1.0)]];
    [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.9, 0.9, 0.9)]];
    [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.0, 1.0, 1.0)]];
    
    animation.values = values;
    [_contentView.layer addAnimation:animation forKey:nil];
}
【2015-05-06 17:27:22 by beyond】



【自编号:304】【cell侧滑ime删除】
1.dataSource的方法:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
此方法就是给一个空的实现滑动也会出现删除按钮!!
2. 必须先删除数据源
        [blockSelf.arrayData removeObjectAtIndex:indexPath.row];
        // 再删除view
        [blockSelf.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
        
        [blockSelf.tableView reloadData];
【2015-05-07 14:40:36 by beyond】



【自编号:305】【scrollView滚动范围】
// 重置contentView的滚动范围必须大于其bounds的高,才能滚动
【2015-05-08 11:43:58 by beyond】



【自编号:308】【方形图片变圆】
70 * 70的话,圆角只要设置成half即可,即:35
// 从xib中加载 实例化一个SynClassCell对象
+ (ParentDetailTopView *)ParentDetailTopView
{
    // mainBundel加载xib,扩展名不用写.xib
    NSArray *arrayXibObjects = [[NSBundle mainBundle] loadNibNamed:@"ParentDetailTopView" owner:nil options:nil];
    ParentDetailTopView *topView = [arrayXibObjects firstObject];
    topView.headImgView.layer.masksToBounds = YES;
    topView.headImgView.layer.cornerRadius = 35.f;
    return  topView;
}
【2015-05-08 17:16:50 by beyond】



【自编号:309】【关于xcode自己revoke(吊销)certificate(证书)的问题】
原因:新target运行项目的时候,提示找不到描述文件;xcode提议 自动fix issue
描述:这时候,xcode会 revoke(吊销)原来的certificate(证书),因此,与原来证书相关联的描述文件,全部会失效;
解决方法:正确的做法是:从团队其他人员拷贝描述文件到本机,双击导入;在xcode项目配置的设置中 选择刚才导入的描述文件,进而选择code sign identity
【2015-05-08 17:40:55 by beyond】



【自编号:310】【框架请求失败,提示405不支持POST,只allow GET】
位于类:AFHTTPRequestOperation.m
位于方法:
- (void)setCompletionBlockWithSuccess:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success
                              failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure;

具体代码:

                id responseObject = self.responseObject;
                
【2015-05-11 14:30:08 by beyond】



【自编号:311】【iphone6截屏750 X 1334】【2015-05-11 16:30:30 by beyond】



【自编号:312】【JSBadgeView 是一个可定制的在视图上显示徽章的 iOS 组件】【2015-05-12 10:06:48 by beyond】



【自编号:314】【奇怪的问题】
在cell的xib文件中 添加了一个控件如label,并且IBOutlet连线,但是:运行的时候该label却没有初始化显示为nil
【2015-05-12 15:58:23 by beyond】



【自编号:315】【webview执行js函数注意事项】
url has prefix 判断时,要注意ios统一加http://并且注意大小写哦~~~
字符串参数要用单引号
数字不用
true用数字1
并且jsonString必须使用NSJSONReadingMutableLeaves,
不能使用pretty风格,如下所示:
NSData *data = [NSJSONSerialization dataWithJSONObject:bigDict options:NSJSONReadingMutableLeaves error:nil];

NSString *jsonString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];

【2015-05-14 10:56:55 by beyond】



【自编号:320】【自动布局按钮排列】
先全部与父类对齐,然后设置一下乘积因子
【查看原文】 【2015-05-15 15:36:58 by beyond】



【自编号:321】【No matching provisioning profiles found】
问题:Your build settings specify a provisioning profile with the UUID “dedebf56-8f41-4af9-aeb8-5ec59fe02fedbeyond”, however, no such provisioning profile was found.  Xcode can resolve this issue by downloading a new provisioning profile from the Member Center.
解决方法:
targets---build settings---- code signing----provisioning profile----debug
【2015-05-15 17:27:03 by beyond】



【自编号:322】【按钮,左图 右文字】
#import "OperationBtn.h"
#define kMargin 5
@implementation OperationBtn

- (void)setHighlighted:(BOOL)highlighted
{
    // do nothing 就是取消默认的高亮状态
}
- (CGRect)imageRectForContentRect:(CGRect)contentRect
{
    // 图片等宽高(15,整个按钮是25,图片左上边距全是5)
    CGFloat wh = contentRect.size.height - kMargin - kMargin ;
    CGRect rect = CGRectMake(kMargin, kMargin, wh, wh);
    return rect;
}

- (CGRect)titleRectForContentRect:(CGRect)contentRect
{
    // 文字居右 (图片15*15)
    CGFloat wh = contentRect.size.height - kMargin - kMargin;
    CGFloat x = kMargin + 15 + 3;
    CGFloat y = kMargin + 3;
    CGRect rect = CGRectMake(x, kMargin,contentRect.size.width - x, wh);
    return rect;
}

- (void) setEnabled:(BOOL)enabled
{
    
    DLog(@"setEnabled方法:%d",enabled  );
    [super setEnabled:enabled];
}

@end

【2015-05-15 17:41:58 by beyond】



【自编号:323】【UIAlertView+Block】
#import 
typedef void (^UIAlertViewBlock)(UIAlertView *alertView, NSInteger buttonIndex);
typedef void (^ConfirmBlock)(void);
@interface UIAlertView(Block) 
@property (nonatomic,copy)ConfirmBlock confirmBlock;
@property (nonatomic,copy)UIAlertViewBlock clickBlock;
// 必须手动用运行时绑定方法
- (void)setConfirmBlock:(ConfirmBlock)confirmBlock;
- (ConfirmBlock)confirmBlock;


- (void)setClickBlock:(UIAlertViewBlock)clickBlock;
- (UIAlertViewBlock)clickBlock;
@end

//====================

#import "UIAlertView+Block.h"
#import 
@implementation UIAlertView(Block)

// 必须手动用运行时绑定方法
- (void)setConfirmBlock:(ConfirmBlock)confirmBlock
{
    objc_setAssociatedObject(self, @selector(confirmBlock), confirmBlock, OBJC_ASSOCIATION_COPY_NONATOMIC);
    if (confirmBlock == NULL) {
        self.delegate = nil;
    }
    else {
        self.delegate = self;
    }
}

- (ConfirmBlock)confirmBlock
{
    return objc_getAssociatedObject(self, @selector(confirmBlock));
}


// 必须手动用运行时绑定方法
- (void)setClickBlock:(UIAlertViewBlock)clickBlock
{
    objc_setAssociatedObject(self, @selector(clickBlock), clickBlock, OBJC_ASSOCIATION_COPY_NONATOMIC);
    if (clickBlock == NULL) {
        self.delegate = nil;
    }
    else {
        self.delegate = self;
    }
}

- (UIAlertViewBlock)clickBlock
{
    return objc_getAssociatedObject(self, @selector(clickBlock));
}


#pragma mark - UIAlertViewDelegate
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 1) {
        // 确定
        if (self.confirmBlock) {
            // self.confirmBlock(self, buttonIndex);
            self.confirmBlock();
        }
    } else {
        // 取消或其他
    }
    
    if (self.clickBlock) {
        self.clickBlock(self, buttonIndex);
        
    }
    
}
@end

//====================
// 发送请求,删除
        UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"温馨提示" message:@"您确定要放弃发布并返回吗?" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
        alertView.confirmBlock = ^(){
            // 调用父类的返回
            [super doBack:sender];
        };
        [alertView show];
【2015-05-18 11:27:46 by beyond】



【自编号:324】【webview死活不执行js代码】
webview加载本地html需要时间,同时,通过id向服务器获取详情也需要时间,因此:很可能当服务器已经获取到detail信息时,本地的html尚未加载完毕,故出现上述情况

    
【2015-05-18 14:51:40 by beyond】



【自编号:325】【通知】
- (void)xxxNoti:(NSNotification *)noti
{
        //获取键盘的高度
        NSDictionary *dict = [noti userInfo];
}

- (void)dealloc
{
    [[NSNotificationCenter defaultCenter]removeObserver:self];
}
// 监听支付成功
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(paySuccess) name:@"notificationCenter_paySuccess" object:nil];

[[NSNotificationCenter defaultCenter] postNotificationName:@"notificationCenter_paySuccess" object:nil];
【2015-05-19 10:58:54 by beyond】



【自编号:326】【xcode6建分类】
左上角file菜单---》new File---->Objective-c File---->Category
【2015-05-20 11:59:22 by beyond】



【自编号:327】【金额用NSNumber接收,必须strong引用 否则 内存释放,崩掉】
//金额
@property (nonatomic,strong) NSNumber *orderPrice;

double currentPrice = [model.FCurrentPrice doubleValue];
    _topView.currentLabel.text = [NSString stringWithFormat:@"¥%.02lf",currentPrice];


【2015-05-20 15:35:53 by beyond】



【自编号:330】【label中显示表情】 【查看原文】 【2015-05-21 14:21:03 by beyond】



【自编号:331】【data-->string-->OC对象】
(lldb) po data
<7b225374 61747573="" 436f6465="" 223a3530="" 302c2245="" 72726f72="" 4d657373="" 61676522="" 3a22e794="" a8e688b7="" e4b88de5="" ad98e59c="" a8e68896="" e5af86e7="" a081e994="" 99e8afaf="" efbc8122="" 2c22436f="" 6e74656e="" 74223a6e="" 756c6c7d="">

(lldb) po responseString
{"StatusCode":500,"ErrorMessage":"用户不存在或密码错误!","Content":null}

2015-05-21 14:26:31.952 JZH[161:60b] __70-[NetRequest initWithAction:userId:password:otherParam:completeBlock:]_block_invoke [Line 209] responseObject ==== {
    Content = "";
    ErrorMessage = "\U7528\U6237\U4e0d\U5b58\U5728\U6216\U5bc6\U7801\U9519\U8bef\Uff01";
    StatusCode = 500;
}
<!--7b225374-->
【2015-05-21 14:32:58 by beyond】



【自编号:332】【反斜杠】
在吗 NSString 如何表示反斜杠呀 \  
NSString *path = @"main\";
打一个错误, \和“挨一起就出错,打两个 NSString *path = @"main\\";可以,但是后面
[path appendString @"d盘"];以后,
实际的path内容为"main\\d盘" 怎么弄一个单反斜杠呀??
NSString *str = [NSString stringWithFormat:@"%@\\%@",@"main",@"d盘"];
    NSLog(@"str:%@",str);
我发现了,这是个显示的问题,在Debuger Console里可以正常显示,在调试中却显示成两个斜杠,转意字符应该是好使的,即NSString中,""\\"",就是 一个"\" 的转意字符,和c的和c++的一样,只是调试时显示的值有bug罢了。
【2015-05-21 14:56:42 by beyond】



【自编号:333】【禁用单个页面手势滑动返回功能】
在有的时候,我们不需要手势返回功能,那么可以在页面中添加以下代码:
- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];

    // 禁用 iOS7 返回手势
    if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
        self.navigationController.interactivePopGestureRecognizer.enabled = NO;
    }
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];

    // 开启
    if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
        self.navigationController.interactivePopGestureRecognizer.enabled = YES;
    }
}
#define KLNavigationBarHidden [self.navigationController setNavigationBarHidden:YES animated:YES];
#define KLNavigationBarShow [self.navigationController setNavigationBarHidden:NO animated:YES];
【2015-05-21 17:06:11 by beyond】



【自编号:334】【Localizable.strings】
//
//  Localizable.strings
//  JZH 本地资源文件
//
//  Created by beyond on 15/3/19.
//  Copyright (c) 2015年 beyond. All rights reserved.
//

"appName"="XXX";
"login_now"="立即登录";
"vip_showmsg"="请联系您孩子的班主任开通VIP服务";

NSString *str = NSLocalizedString(@"vip_showmsg", nil);
    UIActionSheet *sheet = [[UIActionSheet alloc]initWithTitle:str delegate:self cancelButtonTitle:@"关闭" destructiveButtonTitle:@"购买VIP" otherButtonTitles:@"联系客服", nil];
    [sheet showInView:self.view];
【2015-05-21 17:40:28 by beyond】



【自编号:335】【label图文混排CBEmotionView】
 使用core text 和 core graphics 实现的文字与表情图片的并排绘制
【2015-05-22 09:40:43 by beyond】



【自编号:340】【IB控件用weak,String用copy,delegate用weak,block用copy,对象类型用Strong,基本类型用assign】
@property (nonatomic,weak) IBOutlet UILabel *label;
- (IBAction)xxxBtnClicked:(UIButton *)sender;
【2015-05-22 11:27:32 by beyond】



【自编号:342】【只要约束改变后,就要手动刷新对应的view】
_topView.bigImgHeightConstraint.constant = 0;
    [UIView animateWithDuration:0.3 animations:^{
        [self.view layoutIfNeeded];
        [_topView layoutIfNeeded];
    }];
【2015-05-22 14:14:21 by beyond】



【自编号:343】【奇怪的bug】
问题描述:
1、tableView是通过IB,并且有自动布局;
2、headView是通过代码创建的
3、给tableView加headView,没有问题
4、给tableView加footerView,当用代码创建时,也没有问题
5、但是:当footerView是用自动布局时,tableView首次展示时,footView高度为0;
但是,当jump到一个控制器,并且再次返回时,tableView再次显示,此时footView高度正常了。。。
问题原因:
猜测是:tableView的自动布局影响的
解决方法:
当前 想到的是:线程延迟几秒再给tableView设置footView
self.tableView.tableHeaderView = self.headView;
    _footerView = [RowView RowView];
    // 这里加个延迟,不然会高度为0,应该是自动布局导致的问题
    kWeakSelf
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.05 * NSEC_PER_SEC)),dispatch_get_main_queue(), ^{
        kStrongSelf        
        strongSelf.tableView.tableFooterView = _footerView;
        [UIView animateWithDuration:5 animations:^{
            [strongSelf.view layoutIfNeeded];
            [strongSelf.tableView layoutIfNeeded];
        }];
    });
【2015-05-22 14:43:58 by beyond】



【自编号:345】【正则,表情匹配{:001:}对应的是@"\\{:\\d\\d\\d:\\}",注意括号都要转义】
@"\\{:\\d\\d\\d:\\}"

//反解析 表情文字
+(NSString *) FContentPrettyFaceText:(NSString *)faceText
{
    NSString *str = faceText;
    NSString *pattern = @"\\{:\\d\\d\\d:\\}";
    NSError *error = NULL;
    //定义正则表达式
    NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:pattern options:0 error:&error];
    //使用正则表达式匹配字符
    NSArray *arr = [regex   matchesInString:str options:0 range:NSMakeRange(0, [str length])];
    NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle]pathForResource:@"facesDic.plist" ofType:nil]];
    if (arr.count != 0)
    {
        for (long i = arr.count - 1; i >= 0; i--) {
            NSTextCheckingResult *result = arr[i];
            NSRange range = [result range];
            // 开始位置比如:9
            int loc = range.location;
            // 长度固定是 7
            int len = range.length;
            // {:067:}
            NSString *subStr = [str substringWithRange:range];
            NSString *key = [subStr substringWithRange:NSMakeRange(2, 3)];
            // key:067
            NSString *value = [dict objectForKey:key];
            // [爱心]
            // 首
            NSString *head = [str substringToIndex:loc];
            // 尾
            NSString *tail = [str substringFromIndex:loc + len];
            str = [NSString stringWithFormat:@"%@%@%@",head,value,tail];
        }
    }
    return str;
}
【2015-05-22 16:34:49 by beyond】



【自编号:346】【xib中的cell无故多出一个半透明灰灰的40高、300宽的label,通过po打印,发现是两个label,猜测是contentLabel和detailLabel】
产生原因:是由于在xib选择了一次cell的accessory为detail,结果 在xib代码中 添加了两个label,
因此,即使 再次将accessory选择为no,那两个label依然在xib代码中。。。。
(lldb) po self
>

(lldb) po self.contentView
; layer = >

(lldb) po [self.contentView subviews]
<__nsarraym 0x6ffb850="">(
>,
>,
>,
>,
>,
>,
>
)
<!--__nsarraym-->
【2015-05-22 17:22:26 by beyond】



【自编号:347】【导航标题】
self.navigationItem.title = @"发布";
【2015-05-25 10:36:27 by beyond】



【自编号:348】【判断是否安装weixin】
[WXApi isWXAppInstalled]方法无效
使用下面这个
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"weixin://"]])
    {
        NSLog(@"OK weixin://");
    }
【2015-05-25 16:43:15 by beyond】



【自编号:358】【3G4G自动下载图片】
#import "UIImageView+Download.h"
// 异步下载图片
#import "UIImageView+WebCache.h"
#import "KLNetworkStatus.h"
#import "KLTools.h"
@implementation UIImageView (Download)
- (void)downloadImgWithUrlString:(NSString *)urlString placeHolderImgName:(NSString *)placeHolderImgName
{
    if (!(urlString.length > 0)) {
        //没有图片,直接使用默认图
        self.image = [UIImage imageNamed:placeHolderImgName];
        return;
    }
    
    NSURL *url = [NSURL URLWithString:urlString];
    // 1.先从缓存中取,如果缓存中有:直接设置
    SDWebImageManager *manager = [SDWebImageManager sharedManager];
    BOOL isImgAlreadyExists = [manager cachedImageExistsForURL:url];
    if (isImgAlreadyExists) {
        UIImage *image = [manager.imageCache imageFromDiskCacheForKey:urlString];
        [self setImage:image];
        return;
    }
    // 2.如果缓存中没有,如果是WIFI,下载
    BOOL isWifi = [[KLNetworkStatus sharedKLNetworkStatus] isReachableViaWifi];
    if (isWifi) {
        [self sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:placeHolderImgName]];
        return;
    }
    // 3.如果是3G/4G,则要再进行判断用户是否开启了 自动下载
    BOOL isWWAN = [[KLNetworkStatus sharedKLNetworkStatus] isReachableViaWWAN];
    if (isWWAN) {
        BOOL isAllowDownload = [KLTools isNetworkDownloadSet];
        if (isAllowDownload) {
            [self sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:placeHolderImgName]];
            return;
        }
    }
}
@end

【2015-05-29 17:21:21 by beyond】



【自编号:362】【返回之前,必须退出键盘】
#pragma mark - 返回提示
// 返回,由于是发布页面,所以要检查 提示 防止误操作
- (void)back:(id)sender
{
    BOOL hasSomething = [self formHasSomething];
    if (hasSomething) {
        // 提示
        // 发送请求,删除
        UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"温馨提示" message:@"您确定要放弃发布并返回吗?" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
        alertView.confirmBlock = ^(){
            // 调用父类的返回
            [super back:sender];
        };
        [alertView show];
        return;
    }else{
        [self.view endEditing:YES];
        [super back:sender];
    }
}
【2015-06-01 14:08:16 by beyond】



【自编号:363】【label文字左边距】
UIView *leftview = [[UIView alloc] initWithFrame:frame];  
    textField.leftViewMode = UITextFieldViewModeAlways;  
    textField.leftView = leftview; //imageView 
【2015-06-01 15:47:13 by beyond】



【自编号:365】【每一组的最新记录:分组之前 先排序】
select max(FTime),* FROM DynamicInfoTable WHERE FUID = 'd441e1d7-2362-4c7e-9486-37fd834b3232' group by FOrgID,FType order by max(FTime) DESC
【2015-06-02 17:45:23 by beyond】



【自编号:367】【评论提示后返回】
[SVProgressHUD showSuccessWithStatus:@"提交成功"];
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                [blockSelf.navigationController popViewControllerAnimated:YES];
            });
【2015-06-03 14:04:50 by beyond】



【自编号:381】【给分类添加属性】
// Declaration

@interface MyObject (ExtendedProperties)
@property (nonatomic, strong, readwrite) id myCustomProperty;
@end

// Implementation

static void * MyObjectMyCustomPorpertyKey = (void *)@"MyObjectMyCustomPorpertyKey";

@implementation MyObject (ExtendedProperties)

- (id)myCustomProperty
{
        return objc_getAssociatedObject(self, MyObjectMyCustomPorpertyKey);
}

- (void)setMyCustomProperty:(id)myCustomProperty
{
        objc_setAssociatedObject(self, MyObjectMyCustomPorpertyKey, myCustomProperty, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

@end

【2015-06-04 15:46:27 by beyond】



【自编号:382】【带暂停和继续的NSTimer】
#import 

@interface NSTimer (Pause)
@property (nonatomic, strong, readwrite) NSString *state;
-(void)pause;
-(void)resume;
@end
///////////////////////////////////////////////////////////////////////////
#import "NSTimer+Pause.h"
#import 
static void *state = (void *)@"state";
@implementation NSTimer (Pause)
-(void)pause
{
    if (![self isValid]) {
        return ;
    }
    [self setFireDate:[NSDate distantFuture]]; //如果给我一个期限,我希望是4001-01-01 00:00:00 +0000
}
-(void)resume
{
    if (![self isValid]) {
        return ;
    }
    [self setFireDate:[NSDate date]];
}
- (NSString *)state
{
    return objc_getAssociatedObject(self, state);
}
- (void)setState:(NSString *)s
{
    objc_setAssociatedObject(self, state, s, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
@end
【2015-06-04 16:42:40 by beyond】



【自编号:385】【scrollView不接受点击事件,是因为事件传递失败】
//
//  MyScrollView.m
//  JZH
//
//  Created by xss on 15/6/6.
//  Copyright (c) 2015年 beyond.com All rights reserved.
//  不一定要用继承,可以使用分类

#import "MyScrollView.h"
#import "CoView.h"
@implementation MyScrollView
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    
    if(!self.dragging)
        
    {
        UITouch *touch = [touches anyObject];
        CGPoint loc = [touch locationInView:self];
        // x y转成coView中的坐标
        CGFloat x = loc.x - 10;
        CoView *coView = (CoView *)[self viewWithTag:5267];
        CGFloat y = loc.y - coView.y;
        CGPoint newLoc = [coView convertPoint:loc fromView:self];
        // 经过验证:x == newLoc.x   y == newLoc.y
        x = newLoc.x;
        y = newLoc.y;
        // 现在就是通过point 算出 row,col,进而的推算出i
        int col = x/(kBtnWH+kBtnMarginH);
        int row = y/(kBtnWH+kBtnMarginV);
        int i = row*kBtnColumnNum + col;
        [[self nextResponder] touchesBegan:touches withEvent:event];
        // 注意,coView处理的时候,i越界的情况要处理;i从0开始
        DLog(@"--点了第%d个---",i);
        [coView btnTouched:i];
        
    }
    [super touchesBegan:touches withEvent:event];
    
    //NSLog(@"MyScrollView touch Began");
    
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event

{
    
    if(!self.dragging)
        
    {
        
        [[self nextResponder] touchesEnded:touches withEvent:event];
        
    }
    
    [super touchesEnded:touches withEvent:event];
    
}
@end

【2015-06-08 17:03:48 by beyond】



你可能感兴趣的:(ios,问题,xcode)