码迷,mamicode.com
首页 > 其他好文 > 详细

工作中常用到的一些方法集合

时间:2014-09-29 11:18:07      阅读:203      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   http   color   io   os   ar   for   

  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;

 

 

工作中常用到的一些方法集合

标签:des   style   blog   http   color   io   os   ar   for   

原文地址:http://www.cnblogs.com/ndyBlog/p/3999480.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!