工作中常用到的一些方法集合
1 1.取较大文件,大图 2 NSString *Path = [[NSBundle mainBundle] pathForResource:@"data" ofType:@"plist"]; 3 NSString *str = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil]; 4 NSString *path = [[NSBundle mainBundle] pathForResource:@"bg_00" ofType:@"png"]; 5 UIImage *bgImage = [UIImage imageWithContentsOfFile:path]; 6 7 2.警告框 8 - (void)showAlertViewWithInfo:(NSString *)info{ 9 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:info delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定",nil]; 10 [alert show]; 11 [alert release]; 12 } 13 3.用类方法创建一个indexpath实例 14 NSIndexPath *indexPath= [NSIndexPath indexPathForRow:_dataArray.count-1 inSection:0]; 15 //让tableView滚动到指定的indexPath 16 [_tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES]; 17 4.两秒后,执行自动回复的方法 18 [self performSelector:@selector(autoSpeak) withObject:nil afterDelay:2.0]; 19 5.让图片转动 20 [UIView animateWithDuration:0.1 animations:^{ 21 _refreshView.transform = CGAffineTransformRotate(_refreshView.transform, 1); 22 }]; 23 6.收键盘 24 - (BOOL)textFieldShouldReturn:(UITextField *)textField{ 25 [textField resignFirstResponder]; 26 return YES; 27 } 28 7.计算Label高度 29 CGSize size = [chatText sizeWithFont:[UIFont systemFontOfSize:18] constrainedToSize:CGSizeMake(250, 999) lineBreakMode:NSLineBreakByCharWrapping]; 30 8.xml解析 31 NSString *str = [NSString stringWithFormat:@"http://iappfree.candou.com:8080/free/applications/522582006?currency=rmb&format=xml"]; 32 **NSString *String =[NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil]; 33 **NSData *data = [String dataUsingEncoding:NSUTF8StringEncoding]; 34 NSURL *url = [NSURL URLWithString:str]; 35 NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url]; 36 _urlConnecton = [[NSURLConnection alloc]initWithRequest:urlRequest delegate:self]; 37 38 GDataXMLDocument *doc = [[GDataXMLDocument alloc]initWithData:_data options:0 error:nil]; 39 GDataXMLElement *q = [doc rootElement]; 40 NSLog(@"%@",q); 41 NSArray *users = [doc nodesForXPath:@"//xml" error:nil]; 42 // NSLog(@"%d",users.count); 43 for (GDataXMLElement *user in users) { 44 GDataXMLElement *ds = [[user elementsForName:@"iconUrl"]lastObject]; 45 NSLog(@"%@",ds.stringValue); 46 [_array1 addObject:ds.stringValue]; 47 48 9.//标签栏创建与添加 标签栏高度49,item图片(30*30) 49 NSArray *controllers = [NSArray arrayWithObjects:navController,second,third,four, nil]; 50 self.viewControllers = controllers; 51 52 UITabBarController *tabController = [[UITabBarController alloc] init]; 53 tabController.delegate = self; 54 tabController.viewControllers = controllers; 55 56 10. ASI JSONSerialization解析 57 ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:FreeUrlString]]; 58 request.delegate = self; 59 [request startAsynchronous]; 60 - (void)requestFinished:(ASIHTTPRequest *)request{ 61 if (request.responseData) { 62 id result = [NSJSONSerialization JSONObjectWithData:request.responseData options:NSJSONReadingMutableContainers error:nil]; 63 if ([result isKindOfClass:[NSDictionary class]]) { 64 NSDictionary *dic = (NSDictionary *)result; 65 NSLog(@"dic:%@",dic); 66 11.视图控制器风格 67 self.navigationController.navigationBar.barStyle = UIBarStyleBlack; 68 12.初始化搜索条 69 _searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0,0,320,44)]; 70 _searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:_searchBar contentsController:self] 71 _searchDisplayController.searchResultsDelegate = self 72 _searchDisplayController.searchResultsDataSource = self 73 13.导航栏自定义按钮 74 UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithCustomView:btn]; 75 self.navigationItem.leftBarButtonItem = item; 76 14.系统样式按钮 77 UIBarButtonItem *addItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addPerson:)]; 78 self.navigationItem.rightBarButtonItem = addItem; 79 15.判断方法是否存在 80 if ([_delegate respondsToSelector:@selector(sendDetailValue:)]) { 81 [_delegate sendDetailValue:self]; 82 16.字典 83 NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithObjectsAndKeys:name,@"personName",number,@"phoneNumber",nil]; 84 17.定时器 85 [NSTimer scheduledTimerWithTimeInterval:0.02 target:self selector:@selector(scrollUpdate) userInfo:nil repeats:YES]; 86 18.单例 87 #define APP ((AppDelegate*)[UIApplication sharedApplication].delegate) 88 89 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; 90 [defaults setObject:@"tag" forKey:@"open"]; 91 //将数据同步给应用程序的NSUserDefaults实例(文件) 92 [defaults synchronize]; 93 19.跳转到指定的视图控制器 94 [self.navigationController pushViewController:sub animated:YES]; 95 [self.navigationController popToViewController:[viewControllers objectAtIndex:1] animated:YES]; 96 20. 工具栏 97 [self.navigationController setToolbarHidden:NO animated:YES]; 98 UIBarButtonItem *item1 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:nil]; 99 self.toolbarItems = items; 100 21.从父类中移除 101 [self.view removeFromSuperview]; 102 22.HomeView *hView = (HomeView *)[self.superview.subviews objectAtIndex:0]; 103 23.点击手势 104 UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imageViewTaped)]; 105 [imageView1 addGestureRecognizer:tap]; 106 [tap release]; 107 24.文字内容会显示成暗文 textField.secureTextEntry = YES; 108 25.父视图可以通过subviews的下标(objectAtIndex:)拿到指定的子视图 109 NSArray *views = self.window.subviews; 110 [[views objectAtIndex:0] setBackgroundColor:[UIColor purpleColor]]; 111 26.设置视图的变化模式,UIViewAutoresizingFlexibleWidth 宽度随着父视图自动变化,UIViewAutoresizingFlexibleHeight 高度随着父视图自动变化 112 topView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; 113 27.动画效果(引包) 114 CATransition *ca = [CATransition animation]; 115 [ca setDuration:1.0f]; 116 //fade', `moveIn', `push' and `reveal'. Defaults to `fade' 117 ca.type = @"reveal"; 118 ca.subtype = kCATransitionFromRight; 119 [self.navigationController.view.layer addAnimation:ca forKey:nil]; 120 121 [UIView beginAnimations:nil context:nil]; 122 [UIView setAnimationDelegate:self]; 123 [UIView setAnimationDidStopSelector:@selector(btnClicked)]; 124 [UIView setAnimationDuration:1.5]; 125 [UIView setAnimationDelay:2]; 126 [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; 127 view1.frame =CGRectMake(30, 50, 0, 0); 128 [UIView commitAnimations]; 129 130 131 28.数据 132 qewr-2:guojinbao qianfeng$ sqlite3 data.db 133 sqlite> drop table RPTABLE; 134 insert into RPTABLE(id,name,rp) values(1,'Jianjian',13); 135 delete from RPTABLE where id=6; 136 update RPTABLE set rp=59 where id =5; 137 select *from RPTABLE where rp<=60 and rp>=50; 138 select *from RPTABLE where rp>=60 or rp<=50; 139 select *from RPTABLE limit 2; 140 降序/升序select *from RPTABLE order by rp desc/asc; 141 select count(*) from RPTABLE; 142 select sum(rp) from RPTABLE; 143 select avg(rp) from RPTABLE; 144 create table JCTABLE (id INTEGER PRIMARY KEY AUTOINCREMENT,name,jc); 145 select RPTABLE.id,RPTABLE.name,RPTABLE.rp,JCTABLE.jc from RPTABLE,JCTABLE where RPTABLE.id=JCTABLE.id;
转载于:https://www.cnblogs.com/ndyBlog/p/3999480.html
工作中常用到的一些方法集合相关推荐
- hashmap应用场景_工作中常用到的Java集合有哪些?应用场景是什么?
秋招Java面试大纲:Java+并发+spring+数据库+Redis+JVM+Netty等 疫情期间"闭关修炼",吃透这本Java核心知识,跳槽面试不心慌 Spring全家桶笔记 ...
- 工作中常用的Stream集合处理
前言:Java8的新特性主要是Lambda表达式和流,当流和Lambda表达式结合起来一起使用时,因为流申明式处理数据集合的特点,它允许把函数作为一个方法的参数,让我们的代码更优雅简洁. Java8最 ...
- java常用工具类_java(二):工作中常用到的工具类
工作中大家要用到很多工具类,第三方的jar中有很多现成的工具类符合自己的项目需要,这个时候就不需要去重复造轮子了,从而节省了很多时间,大家可以利用这些时间去做其它重要的事情,如果没有符合自己的工具类, ...
- 实战!工作中常用到哪些设计模式
前言 平时我们写代码呢,多数情况都是流水线式写代码,基本就可以实现业务逻辑了.如何在写代码中找到乐趣呢,我觉得,最好的方式就是:使用设计模式优化自己的业务代码.今天跟大家聊聊日常工作中,我都使用过哪些 ...
- 工作中常用,实用工具推荐!
原文:工作中常用,实用工具推荐! Red Gate 家族 大名鼎鼎的RedGate,相信大家都不会陌生,Reflector就是它家做的.这里就不介绍了.我本地安装的是09年下的一个套装,我介绍下常用的 ...
- 工作中常用的 6 种设计模式!
前言 哈喽,大家好. 平时我们写代码呢,多数情况都是流水线式写代码,基本就可以实现业务逻辑了.如何在写代码中找到乐趣呢,我觉得,最好的方式就是:使用设计模式优化自己的业务代码.今天跟大家聊聊日常工作中 ...
- office怎么像wps一样多栏_工作中常用的两个工作软件,你觉得WPS和office哪个好用?...
工作中常用的两个工作软件,分别是WPS与office,对于这两个软件的适用性,大家也是说法不一,那么就WPS和office哪个好用,这里就来简单和大家闹闹. 一.占用空间 安装包 安装后占用的空间 不 ...
- 分享一些工作中常用的工具软件,值得收藏!
前言 我之前分享过一篇:分享一些常用的网站和工具,值得收藏!,今天再分享一波关于工作中常用的工具软件! 文章首发在公众号(月伴飞鱼),之后同步到个人网站:http://xiaoflyfish.cn/ ...
- php中的数组有哪几种方法,PHP中常用的遍历数组方法有几种,分别是什么?( )...
PHP中常用的遍历数组方法有几种,分别是什么?( ) 更多相关问题 序列对心电触发的原理叙述,正确的是()A.是利用心电图的R波触发采集MR信号B.是利用心电图的T波触 静脉输血法的评价 有关急性梗阻 ...
最新文章
- 企业级微服务架构统一安全认证设计与实践!
- Coursera algorithm II PA4
- 突破androidstudio 的控制
- CISCO专用协议CDP
- Markdown编辑器攻略——字体,字号,颜色
- C#接口-接口的继承
- 材料成型计算机模拟第三版,材料成型计算机模拟实验报告模板学习.doc
- php实现斐波那契数列
- 【转载】使用 gnuplot 在网页中显示数据
- 前端学习(2582):生态圈练习解答
- 【Latex】分数写法区别
- 磁盘性能分析一:IO负载高的判断详解
- Feign Hystrix微服务调用Session传播
- webbench 压力测试软件
- 基于hilbert变换的数字信号_通过Hilbert变换实现移相算法
- win10下载ie浏览器
- javaScript开源大全
- 小丁在加班之JVM优化-内存结构
- RN综合演练,仿美团电商(谢谢你的STAR)
- 操作系统复习题最全(复习看它就够了!!!!!