bug备忘

强烈推荐阅读 《提问的智慧》《如何向开源社区提问题》《如何有效地报告 Bug》,更好的问题更容易获得帮助。

财经新闻接口:http://c.m.163.com/nc/article/list/T1348648756099/0-20.html,0为页数,20为一页多少数据

1,

/**
*  注意数组的格式为可变的,此处直接赋值为不可变的(直接从服务器请求的数组是不可变的)
*/
_followUpRecordViewsArray = [NSMutableArray arrayWithArray:dic[@"data"][@"followUpRecordViews"]];

2.友盟分享默认隐藏未安装应用的分享按钮

3.适用于2种不同的情况的界面(1,有数据2,无数据.在初始化时先将视图统一布局,然后请求数据,请求不到时使用无数据视图,请求到时使用有数据视图)

4.两个界面之间传值使用delegate

5.viewControl的addChidView时的frame位置错乱问题(有可能是融云的接口调用方式有问题/不建议使用此方法进行布局)

6.UI控件添加时,当使用.bottom等时.两个UI空间只能是兄弟关系,不能是父子关系.否则,容易出错.

7.记得勾选tagMemberShip

8.上传appStore的图片时要注意图片尺寸,格式和命名.

建议使用jpg格式的图片

9.字体设置:(UILabel的字符串处理,见adapter https://github.com/Quxiaolei/Adapter)

大小:systemFontOfSize/boldSystemFontOfSize/italicSystemFontOfSize

字体大小自适应:adjustsFontSizeToFitWidth

10.时间戳---->时间字符串(https://github.com/Quxiaolei/Adapter)

11.We noticed that your app did not run at iPhone resolution when reviewed on iPad running iOS 9.0.1, which is a violation of the App Store Review Guidelines.
设备选成iPhone

12.tableView中使用一个xib文件中的两个不同的cell布局
//    取出当前的消息对象
myMessage * message = [_allMessageArray objectAtIndex:indexPath.row];
//    根据消息的对象,判断使用哪个单元格
NSString * cellIdentifier = message.isSelf ? @"cell1" : @"cell2";

if (indexPath.row %2 == 0) {
    CircleTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CircleCell_Article"];
    if(!cell){
        NSArray *cellArray = [[NSBundle mainBundle] loadNibNamed:@"CircleTableViewCell" owner:nil options:nil];
        cell = [cellArray objectAtIndex:0];
    }
    return cell;
}else{
    CircleTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CircleCell_Video"];
    if(!cell){
        NSArray *cellArray = [[NSBundle mainBundle] loadNibNamed:@"CircleTableViewCell" owner:nil options:nil];
        cell = [cellArray objectAtIndex:1];
    }
    return cell;
}

messageTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (!cell)
{
    NSArray * cellArray = [[NSBundle mainBundle] loadNibNamed:@"messageTableViewCell" owner:nil options:nil]; 
    cell = [cellArray objectAtIndex:message.isSelf ? 0 : 1];    
}

13.ERROR ITMS-90049:"This bundle is invalid. The bundle identifier contains disallowed characters. [See the section of the Application Programming Guide entitled The Application Bundle.]"
删除 UMSocial_Sdk_Extra_Frameworks--TencentOpenAPI--TencentOpenApi_IOS_Bundl‌​e.bundle--info.plist

13.默认字体大小17px,定义全局变量适配不同屏幕的字体大小
14.Xcode7 设置代码折叠

15.图片的剪裁

- (UIImage*)stretchableImageWithLeftCapWidth:(NSInteger)leftCapWidthtopCapHeight:(NSInteger)topCapHeight 

[UIImage resizableImageWithCapInsets:]

16.

/**
* 隐藏导航条底部与self.view的分界线
*/
[self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.shadowImage = [[UIImage alloc] init];

17.手指晃动效果(锚点可变)

CGPoint oldAnchorPoint = shakeImageView.layer.anchorPoint;
shakeImageView.layer.anchorPoint = CGPointMake(0.6, 1);
[shakeImageView.layer setPosition:CGPointMake(shakeImageView.layer.position.x + shakeImageView.layer.bounds.size.width * (shakeImageView.layer.anchorPoint.x - oldAnchorPoint.x), shakeImageView.layer.position.y + shakeImageView.layer.bounds.size.height * (shakeImageView.layer.anchorPoint.y - oldAnchorPoint.y))];
//开始动画
CABasicAnimation *momAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
momAnimation.fromValue = [NSNumber numberWithFloat:-0.3];
momAnimation.toValue = [NSNumber numberWithFloat:0.3];
momAnimation.duration = 1;
momAnimation.repeatCount = CGFLOAT_MAX;
momAnimation.autoreverses = YES;
momAnimation.delegate = self;
[shakeImageView.layer addAnimation:momAnimation forKey:@"animateLayer"];

18.   定时器开始时间控制

[_circleAnimationTimer setFireDate:[NSDate distantFuture]];
[_circleAnimationTimer setFireDate:[NSDate date]];

19.runtime的使用

// 类名  
NSString *class =[NSString stringWithFormat:@"%@", params[@"class"]];  
const charchar *className = [class cStringUsingEncoding:NSASCIIStringEncoding];  

// 从一个字串返回一个类  
Class newClass = objc_getClass(className);  
if (!newClass)  
{  
// 创建一个类  
Class superClass = [NSObject class];  
newClass = objc_allocateClassPair(superClass, className, 0);  
// 注册你创建的这个类  
objc_registerClassPair(newClass);  
}  
// 创建对象  
id instance = [[newClass alloc] init];  

// 对该对象赋值属性  
NSDictionary * propertys = params[@"property"];  
[propertys enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOLBOOL *stop) {  
// 检测这个对象是否存在该属性  
if ([self checkIsExistPropertyWithInstance:instance verifyPropertyName:key]) {  
// 利用kvc赋值  
[instance setValue:obj forKey:key];  
}  
}];  

// 获取导航控制器  
UITabBarController *tabVC = (UITabBarController *)self.window.rootViewController;  
UINavigationController *pushClassStance = (UINavigationController *)tabVC.viewControllers[tabVC.selectedIndex];  
// 跳转到对应的控制器  
[pushClassStance pushViewController:instance animated:YES];

20.可变字符串的修改和自定义(相关阅读)

[attributeString addAttribute:NSForegroundColorAttributeName value:MAINCOLOR range:NSMakeRange(0, leftString.length)];
[attributeString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:11.0f] range:NSMakeRange(4, leftString.length - 4)];

[attributeString addAttributes:@{NSForegroundColorAttributeName:MAINCOLOR,NSFontAttributeName:[UIFont systemFontOfSize:11.0f]} range:NSMakeRange(4, leftString.length - 4)];
21.
//在“测”和“试”两字之间插入一张图片
NSString *imageName = @"taobao.png";
NSFileWrapper *imageFileWrapper = [[[NSFileWrapper alloc] initRegularFileWithContents:[[NSImage imageNamed:imageName] TIFFRepresentation]] autorelease];
imageFileWrapper.filename = imageName;
imageFileWrapper.preferredFilename = imageName;

NSTextAttachment *imageAttachment = [[[NSTextAttachment alloc] initWithFileWrapper:imageFileWrapper] autorelease];
NSAttributedString *imageAttributedString = [NSAttributedString attributedStringWithAttachment:imageAttachment];
[attributedString insertAttributedString:imageAttributedString atIndex:1]; 

21.字符的阴影效果

leftLabel.textColor = [UIColor whiteColor];
//            leftLabel.layer.borderWidth = 1.0f;
//            leftLabel.layer.borderColor = [UIColor yellowColor].CGColor;
            [leftLabel setShadowColor:[UIColor grayColor]];
            [leftLabel setShadowOffset:CGSizeMake(1.0f, 1.0f)];
//            leftLabel.textAlignment = NSTextAlignmentCenter;

22.//    沙盒路径
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
23.断点测试

23.导航栏等界面处理效果
// 隐藏导航栏
[[UIApplication sharedApplication] setStatusBarHidden:NO];
self.navigationController.navigationBarHidden = YES;
self.navigationController.navigationBar.translucent = YES;

// 设置内边距
self.automaticallyAdjustsScrollViewInsets = NO;
self.edgesForExtendedLayout = UIRectEdgeAll;
self.extendedLayoutIncludesOpaqueBars = NO;
self.modalPresentationCapturesStatusBarAppearance = NO;

24.cell的分割线控制
 /**
  *  单元格分割线据左侧无边距
 */
_selectTableView.separatorInset = UIEdgeInsetsZero;
_selectTableView.layoutMargins = UIEdgeInsetsZero;
 /**
  *  单元格分割线据左侧无边距
  */
cell.separatorInset = UIEdgeInsetsZero; 
cell.layoutMargins = UIEdgeInsetsZero;

// cell分割线左移
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
} 
25.单元格编辑状态
-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
    //默认没有编辑风格
    if(indexPath.section == 2){
        return UITableViewCellEditingStyleDelete;
    }else{
        return UITableViewCellEditingStyleNone;
    }
}
- (void)tableView:(UITableView*)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath
- (void)tableView:(UITableView*)tableView didEndEditingRowAtIndexPath:(NSIndexPath *)indexPath
//- (void)setEditing:(BOOL)editing animated:(BOOL)animated
//{
//    [super setEditing:editing animated:animated];
//    [_tableView setEditing:YES animated:YES];
//}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle) editingStyle forRowAtIndexPath:(NSIndexPath *) indexPath
{
    //点击删除操作
    if (editingStyle == UITableViewCellEditingStyleDelete) {
     }
}

26.控件禁止多点触控
self.fundSearchButton.exclusiveTouch = YES;

26.让console里可以po出 id类型的信息(正常情况你po id类型的对象会显示error)在终端依次输入下面三行指令

touch ~/.lldbinit
echo display @import UIKit >> ~/.lldbinit
echo target stop-hook add -o \"target stop-hook disable\" >> ~/.lldbinit
27.VC之间的跳转: 相关文章

A.Nav -push-> B      B -pop-> A 

A -present-> B       B -dismiss-> A

实现这样一种情况:

B.Nav -push-> X      X -pop-> A

28.
UIWebView显示相关:
// 获取当前页面的title
NSString *title = [webview stringByEvaluatingJavaScriptFromString:@"document.title"];  
// 获取当前页面的url
NSString *url = [webview stringByEvaluatingJavaScriptFromString:@"document.location.href"];
//获取webView的contentHeight
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    CGFloat height = [[webView stringByEvaluatingJavaScriptFromString:@"document.body.offsetHeight"] floatValue];
    MSLog(@"height == %f", height);
    webView.scrollView.contentSize = CGSizeMake(kScreenWidth, height);
}
WKWebView显示相关:
- (void)webView:(WKWebView *)webView didFinishNavigation:(null_unspecified WKNavigation *)navigation
{
    //获取WKWebView的contentHeight
    // @"document.documentElement.style.webkitUserSelect='none';",禁用网页选中手势
     [webView evaluateJavaScript:@"document.body.offsetHeight;" completionHandler:^(id Result, NSError * error) {
        CGFloat contentHeight = [Result floatValue];
        dispatch_async(dispatch_get_main_queue(), ^{
            if ([self.delegate respondsToSelector:@selector(majordomoWKWebView:webViewContentHeightChanged:)]) {
                [self.delegate majordomoWKWebView:self webViewContentHeightChanged:contentHeight];
            }
        });
    }];
}

29.Xcode免证书真机调试不能调试推送
30,// 从storyboard创建MainViewController
    UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
    ViewController *mainViewController = (ViewController*)[storyboard instantiateViewControllerWithIdentifier:@"ViewController"];
    mainViewController.title = [self.array objectAtIndex:indexPath.row];
    mainViewController.currentIndex = indexPath.row;
    mainViewController.musicList    = self.array;
    [self.navigationController pushViewController:mainViewController animated:YES];

31,打开该应用设置界面
NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
 if ([[UIApplication sharedApplication] canOpenURL:url]) {
         //真机测试是否可用
         [[UIApplication sharedApplication] openURL:url];
          //[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=NOTIFICATIONS_ID"]];
 }

32. // 创建需要的毛玻璃特效类型
  UIBlurEffect*blurEffect= [UIBlurEffecteffectWithStyle:UIBlurEffectStyleLight];

   //  毛玻璃view视图

   UIVisualEffectView*effectView = [[UIVisualEffectViewalloc]initWithEffect:blurEffect];

  //添加到要有毛玻璃特效的控件中

    effectView.frame=self.imageV.bounds;

    [self.imageVaddSubview:effectView];

  //设置模糊透明度

    effectView.alpha=.8f;

33.线程锁:当前这个线程如果没执行完,那么就不会 执行里面的方法(创建单例类时用)

@synchronized(self){

}

//里面的代码永远都只执行一次
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
});

34.cell高度计算:(在设置cell方法中计算高度会使内存爆表,会存在死循环)

     1,在- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath中计算

     2,在数据解析时计算出相应的高度,更新cell数据时刷新控件高度

     3,使用约束自动设置cell高度,需要调用"tableView:estimatedHeightForRowAtIndexPath:"代理方法

35.pch文件的创建

在工程的TARGETS里边Building Setting中搜索Prefix Header,然后把Precompile Prefix Header右边的NO改为Yes:

“$(SRCROOT)/项目名称/pch文件名"

将Precompile Prefix Header为YES,预编译后的pch文件会被缓存起来,可以提高编译速度


36.#define ZCLog(...)  NSLog(__VA_ARGS__) 当工程发布的时候 需要去掉注释 那么只需要将宏定义修改为

   #define ZCLog(...)  //NSLog(__VA_ARGS__)

//调试阶段系统会自动生成DEBUG的宏

#ifdef DEBUG
#define YCLog(...) NSLog(__VA_ARGS__)
#else
#define YCLog(...)
#endif

37.Cannot create __weak reference in file using manual reference counting

38.UIImageJPEGRepresentation
UIImagePNGRepresentation

https://www.google.com/search?site=&source=hp&btnG=Google+%E6%90%9C%E7%B4%A2&q=UIImageJPEGRepresentation+%E5%86%85%E5%AD%98

http://www.cnblogs.com/huangjianwu/p/4575244.html

http://stackoverflow.com/questions/27709036/uploading-image-with-ios-app-to-server-file-size-is-too-large/27709329#27709329

https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIKitFunctionReference/index.html#//apple_ref/c/func/UIImageJPEGRepresentation

https://segmentfault.com/q/1010000004193602

39.新建layout可以更改CollectionView的header样式

    layout.headerReferenceSize = CGSizeMake(320, 160);

40, 齿轮文件地址:~/Library/MobileDevice/Provisioning Profiles

41,NSAssert(nil != publicParam[@"deviceid"], @"");  //断言:断定publicParam[@"deviceid"]不为nil,为nil就抛异常

42,sortUsingComparator:可变集合的内部元素的排序,可以是对象,数字,字母(点击打开链接,点击打开链接)

sortedArrayWithOptions,sortedArrayUsingFunction,sortedArrayUsingSelector,sortedArrayUsingDescriptors

[self.topConversationList sortUsingComparator:^NSComparisonResult(MConversation*  _Nonnull obj1, MConversation*  _Nonnull obj2) {
    long long longlongObj1 = [obj1.topTime longLongValue];
    long long longlongObj2 = [obj2.topTime longLongValue];
    NSNumber*numberObj1 = [NSNumber numberWithLongLong:longlongObj1];
    NSNumber*numberObj2 = [NSNumber numberWithLongLong:longlongObj2];
    return [numberObj2 compare:numberObj1];
}];
43,
int length 4
long length 8
double length 8
long double length 16
long long length 8

44,错误提示:此时是因为自定义的class未实现
Undefined symbols for architecture x86_64:
  "_OBJC_CLASS_$_Books", referenced from:
objc-class-ref in SearchBooks.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
45.OC中的基本log输出
People *p1 = [People new];
//打印\输出对象的地址
NSLog(@"p1 = %p",p1);
//打印当前代码的行号
NSLog(@"line = %d",_LINE_);
//打印当前文件的路径
NSLog(@"file = %s",_FILE_);
//打印所属的方法或者类名
NSLog(@"func = %s",_func_);
46,判断对象是否为空
if (!result_listDict[@"boardname"] || result_listDict[@"boardname"] == [NSNull null]){
    result_list.boardname = @"";
}
47.description:描述函数
当运行 NSLog(@"%@",[teacher description]);时,输出的信息是对象信息 比如 <Teacher: 0x10010c2f0>
原理是调用了 对象 teacher的description方法,description方法是继承于父类的方法。
子类可以对其进行重写来输出用户需要的信息
在子类中:
-(NSString *)description
{
    NSString *des = [NSString stringWithFormat:@"<%@: %p>",isa,self];
    return des;
}
48.判断NSDictionary中是否包含某个key值
if ([[dictionary allKeys] containsObject:key) {
    // contains key
}
if ([dictionary objectForKey:key]) {
    //objectForKey will return nil if a key doesn't exists.
    // contains key
}
49.
//判断字符串是否是整型
- (BOOL)isPureInt:(NSString*)string{
	NSScanner* scan = [NSScanner scannerWithString:string];
    int val;
    return[scan scanInt:&val] && [scan isAtEnd];
}
//判断是否为浮点形:
- (BOOL)isPureFloat:(NSString*)string{
    NSScanner* scan = [NSScanner scannerWithString:string];
    float val;
    return[scan scanFloat:&val] && [scan isAtEnd];
}

//格式化字符串为千分位字符串
+(NSString *)formatBehavior10_4String:(NSString *)decimalString {
    NSNumberFormatter *numFormatter = [[NSNumberFormatter alloc] init];
    [numFormatter setFormatterBehavior:NSNumberFormatterBehavior10_4];
    [numFormatter setNumberStyle:NSNumberFormatterDecimalStyle];
    NSString *numString = [numFormatter stringFromNumber:[NSDecimalNumber decimalNumberWithString:decimalString]];
    return numString;
}

50,duplicate symbol _OBJC_CLASS_$_FundRedemptionViewController in:
项目文件被重复导入
文件/仓库重复导入编译时会报错误
51,设置textField内容距左的左边距
 //设置文本框左边的view
   UITextField *textField = [[UITextField alloc]init];
   textField.frame = CGRectMake(10, 30, 300, 30);
   [self.view addSubview:textField];
   textField.leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 8, 0)];
   //设置显示模式为永远显示(默认不显示)
   textField.leftViewMode = UITextFieldViewModeAlways;
52,iOS8以后cell自动布局(源自: http://my.oschina.net/u/1418722/blog/322623?p=1)

具体到Cell,要求cell.contentView的四条边都与内部元素有约束关系。

self.tableView.estimatedRowHeight = 44.0f;

self.tableView.rowHeight = UITableViewAutomaticDimension;

53.设置隐藏tabbar时显示异常,以及原tabbar位置的点击事件无法相应的bug
1,设置父级VC的view的frame为当前屏幕大小
self.view.frame = kScreenBounds;
2,隐藏tabbar:
self.tabBarController.tabBar.frame = CGRectZero;
self.tabBarController.tabBar.hidden = YES;
3,显示tabbar:
self.tabBarController.tabBar.frame = CGRectMake(0, kScreenHeight - 49.0f, kScreenWidth, 49.0f);
self.tabBarController.tabBar.hidden = NO;
(相关文档:
https://www.ianisme.com/ios/1871.html
http://www.cnblogs.com/aBigRoybot/articles/2234487.html
http://blog.csdn.net/miaoshichang/article/details/51769444)

54.使用AFNetWorking进行网络请求可能导致的bug:
错误信息:NSInternalInconsistencyException‘, reason: ‘Invalid parameter not satisfying: URLString‘
parameters参数不建议拼接在URL地址后,parameters不能设置为nil
详细信息: http://www.cnblogs.com/niit-soft-518/p/4012011.html
55.HTTPS的SSL Pinning技术能够防止数据请求代码被抓包/中间人攻击(Charles等使用自定义根证书模拟CA官方)
   1.本地保存服务器的SSL公钥证书
   2.使用AF等接口请求工具,在建立会话链接时会返回服务端是证书文件,将本地文件与服务端证书文件进行对比



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值