博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
iOS工作小结
阅读量:4296 次
发布时间:2019-05-27

本文共 6279 字,大约阅读时间需要 20 分钟。

1.关于在NSobject类中无法声明UImageView *等参数
Framwork要加入UIKit框架,UIImage才能使用

2.打包时选择了表述文件后
只会显示对应的一个证书,只要有多个证书就重启一遍xcode

3.白色字体因为背景图片而看不清如何处理
在背景图片上蒙一层半透明的UIImageView即可

4.bounce可以控制scrollview的反弹效果
为BOOL型变量,可设置

5.在响应事件内切换tabBar

self.tabBarController.selectedIndex = 1;

6.git 快速找到clone地址

git remote -v

7.打包时出现 3D0CC99EBF87D6479CF799461890E07C85685769: no identity found Command /usr/bin/codesign failed with exit code 1 错误
类似错误是证书不对,没运行证书

8.iOS报错[__NSCFNumber length]: unrecognized selector sent to instance 
出现这种报错很大的原因是因为类型给错了,或许你这个数据是从json上解析后得到的,但是需要看一下这个数据是NSString还是NSNumber类型,如果是NSNumber类型的话,你又直接使用NSString类型的变量去接收他,那么肯定会报这样的错误,所以一定要注意数据的类型

9.设置键盘右下角按钮的类型,如:完成

self.searchTextField.returnKeyType = UIReturnKeyDone;

10.当代码创建tableIView后注册的cell为nil时的原因 
1.该tableView被隐藏,查看hidden属性是否为YES
2.是否同一界面存在多个tableView,是的话在需要判断的地方如下处理:
tableView = tableViewA;
tableView = tableViewB;

11.UIButton的UIControlEventTouchUpInside无响应问题 
查看其父控件是否继承了某些类,或直接从父控件中转移到平级即可解决

12.在实现录音长按等效果时,UIButton不需要加长按手势 
使用UIControlEventTouchDown(点下去) 这个按下去的操作来判断
监听抬手动作时用UIControlEventTouchUpInside(点下去弹起来)来判断即可

13.长按手势的开始和结束

-(void)longPress:(UILongPressGestureRecognizer *)gestureRecognizer{    //长按开始    if ([gestureRecognizer state] == UIGestureRecognizerStateBegan) {        [self.voiceSignView.voiceButton setBackgroundImage:[UIImage imageNamed:@"bf1"] forState:UIControlStateNormal];        self.voiceSignView.promptLabel.text = @"松手结束";        self.voiceSignView.cancelButton.hidden = YES;        self.voiceSignView.saveButton.hidden = YES;                //长按结束    } else if ([gestureRecognizer state] == UIGestureRecognizerStateEnded) {            }    }

14.tableView返回顶部,通常使用在下拉刷新时

[self.tableView setContentOffset:CGPointMake(0, 0) animated:YES];

15.presentViewController过去之后navigation不见了或者push操作无法响应 
是因为presentViewController 需要使用的是navigationController的sb ID,换成navigationController的sb ID就可以了。

16.真机测试出现Your build settings specify a provisioning profile with 
1.找到项目中的**.xcodeproj文件,点击右键,show package contents(打开包内容)。
2.打开后找到project.pbxproj文件,用文本编辑器打开。其实就是右键,点击open就好了。
3.打开这个文件后,按command+F,在这个文件中查找“PROVISIONING_PROFILE",找到和这个“
PROVISIONING_PROFILE = "487F3EAC-05FB-4A2A-9EA0-31F1F35760EB"; "PROVISIONING_PROFILE[sdk=iphoneos*]" = "487F3EAC-05FB-4A2A-9EA0-31F1F35760EB";”类似的都删除。
4.然后保存文件,重新打开项目。xcode会提示你重新下载安装provisioning profile文件。下载后安装上就可以。

17.更改segmentControl图片

UIImage * imageSel = [UIImage imageNamed:@"d_seg_sel"];[self.segmentButton setBackgroundImage:[imageSel resizableImageWithCapInsets:UIEdgeInsetsMake(10, 10, 0, 10) resizingMode:UIImageResizingModeStretch] forState:UIControlStateSelected barMetrics:UIBarMetricsDefault];UIImage * imageNor = [UIImage imageNamed:@"d_seg_nor"];[self.segmentButton setBackgroundImage:[imageNor resizableImageWithCapInsets:UIEdgeInsetsMake(10, 10, 0, 10) resizingMode:UIImageResizingModeStretch] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];

18.隐藏UIScrollView的滚动条(同样适用于父类继承自UIScrollView的控件,如UITableView,UICollectionView等)

scrollView.showsVerticalScrollIndicator = FALSE;scrollView.showsHorizontalScrollIndicator = FALSE;

19.关于segmentButton存在多个并排segment而展示不完的解决方法 
1.将字体超过局限的segment的Width进行调整即可
2.使用UICollectionView进行伪装

20.撤回登陆界面 
present对应dismiss
push对应pop

例:如果登陆是

UINavigationController * loginNavigationController = getViewController(@"login", @"Login");    [[[[UIApplication sharedApplication]keyWindow]rootViewController] presentViewController:loginNavigationController animated:YES completion:^{        XS_APP_DELEGATE.tabBarController = nil;    }];

那么取消登陆就是

[self.view endEditing:YES];    [[[[UIApplication sharedApplication]keyWindow]rootViewController] dismissViewControllerAnimated:YES completion:^{    }];

21.计算日期,昨日-今日-以及之后的几天日期

self.dataArray = [[NSMutableArray alloc] init];NSDate * date = [NSDate date];NSDateFormatter * dateFormatter = [[NSDateFormatter alloc] init];[dateFormatter setDateFormat:@"MM.dd"];NSDate * yesterday = [NSDate dateWithTimeInterval:-24 * 60 * 60 sinceDate:date];NSString * yesterdayString = [dateFormatter stringFromDate:yesterday];[self.dataArray addObject:yesterdayString];[self.dataArray addObject:@"今日"];[self.dataArray addObject:@"明日"];NSDate * after;for (int i = 2; i < 6; i ++) {    after = [NSDate dateWithTimeInterval:i * 24 * 60 * 60 sinceDate:date];    NSString * afterString = [dateFormatter stringFromDate:after];    [self.dataArray addObject:afterString];}

22.设置UIButton的UIFont

cancelButton.titleLabel.font = [UIFont fontWithName:@"HelveticaNeue-Bold" size:14];

23.@property和@interface声明变量的区别 
用@interface声明的属性,只能在这个父类中使用,是完全私有的,用@property声明的属性外部是可以访问的,同时,用@property声明的对象系统会给予一个get和set的方法属性,这个是管理内存一个重要的方式 在oc里面,也可以说,用@property可以使用self,可以进行重写的操作,而@interface不可以

24.返回到指定viewController

NSArray * vcArray = self.navigationController.viewControllers;for (UIViewController * vc in vcArray) {                if ([vc isKindOfClass:[XSConfiderSettingTableViewController class]]) {                            [self.navigationController popToViewController:vc animated:YES];           }    }

也可以:

[self.navigationController popToViewController:[vcArray objectAtIndex:index] animated:YES];

其中index可以根据实际情况而定,返回指定第几个viewController

25.如果判断不了arrray[n]是否存在,就判断array.count > n

26.自定义section的文字颜色背景等

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{    UIView * sectionView = [[UIView alloc] init];    sectionView.backgroundColor = [UIColor colorWithRed:242/255.0 green:243/255.0 blue:248/255.0 alpha:1.0];    UILabel * titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(16, 0, 190, 30)];    [titleLabel setFont:[UIFont systemFontOfSize:14]];    titleLabel.textColor = kColor;    titleLabel.text = @"选择开通的套餐服务";    [sectionView addSubview:titleLabel];        return sectionView;}

27.UISwitch的颜色样式无需自定义重写 
直接在其ON Tint属性中设置就行了,当然还有Thumb Tint属性

28.画远离字体的UILabel边框的取巧方法
在内容的两侧加上空格即可撑开边框,如:

NSString * info = @"内容";self.label = [NSString stringWithFormat:@" %@ ", info];

29.一个统一设置label边框的方法(当该类存在多个UILabel控件需要画上边框时)

//统一设置label边框-(void)changeLabelBorder:(UILabel *)label borderColor:(UIColor *)color{    label.layer.masksToBounds = YES;    label.layer.cornerRadius = 7;//圆角    label.layer.borderColor = color.CGColor;//边框颜色    label.layer.borderWidth = 0.5;//边框宽度    label.textColor = color;//字体颜色}

30.静态UITableView的cell箭头设置方法 
在storyBoard中选中tableView选择Accessory ->Disclosure Indicator

转载地址:http://lkdws.baihongyu.com/

你可能感兴趣的文章
vnpy学习11_增加测试评估指标
查看>>
资金流入流出计算方法
查看>>
海龟交易法则07_如何衡量风险
查看>>
海龟交易法则08_风险与资金管理
查看>>
海龟交易法则09_海龟式积木
查看>>
海龟交易法则10_通用积木
查看>>
海龟交易法则14_掌控心魔
查看>>
海龟交易法则15_万事俱备
查看>>
海龟交易法则16_附原版海龟交易法则
查看>>
克罗谈投资策略01_期货交易中的墨菲法则
查看>>
克罗谈投资策略02_赢家和输家
查看>>
克罗谈投资策略03_你所期望的赌博方式
查看>>
克罗谈投资策略04_感觉与现实
查看>>
通向财务自由之路01_导读
查看>>
通向财务自由之路02_成功的决定因素:你
查看>>
中低频量化交易策略研发01_引言
查看>>
中低频量化交易策略研发06_推进的择时策略
查看>>
史丹·温斯坦称傲牛熊市的秘密
查看>>
期货市场技术分析01_理论基础
查看>>
期货市场技术分析02_趋势的基本概念
查看>>