工作中常用到的一些方法集合
生活随笔
收集整理的這篇文章主要介紹了
工作中常用到的一些方法集合
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
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.用類方法創(chuàng)建一個indexpath實例
14 NSIndexPath *indexPath= [NSIndexPath indexPathForRow:_dataArray.count-1 inSection:0];
15 //讓tableView滾動到指定的indexPath
16 [_tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];
17 4.兩秒后,執(zhí)行自動回復的方法
18 [self performSelector:@selector(autoSpeak) withObject:nil afterDelay:2.0];
19 5.讓圖片轉(zhuǎn)動
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.//標簽欄創(chuàng)建與添加 標簽欄高度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.系統(tǒng)樣式按鈕
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 //將數(shù)據(jù)同步給應用程序的NSUserDefaults實例(文件)
92 [defaults synchronize];
93 19.跳轉(zhuǎn)到指定的視圖控制器
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.文字內(nèi)容會顯示成暗文 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.數(shù)據(jù)
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;
?
轉(zhuǎn)載于:https://www.cnblogs.com/ndyBlog/p/3999480.html
總結
以上是生活随笔為你收集整理的工作中常用到的一些方法集合的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 我的第一个web开发框架
- 下一篇: 如何通过预加载器提升网页加载速度