iOS
LoginViewController *loginview = [[LoginViewController alloc]init];
loginview.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:[[UIView alloc] initWithFrame:CGRectZero]];
[self.navigationController pushViewController:loginview animated:YES];
loginview 为跳转目标页,这样写跳转过去就好了。
2. 我们有时候写表,数据得后来加,但是我们写完之后发现数据不见了,尤其cell.detailTextLabel.text,怎么破,用[tableview reloadData],加完接口来过的数据马上就用这个,就出来了。
5. 有时候我们需要把手机的缓存清除一下,我照着大神是这样写的
dispatch_async(
dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)
, ^{
NSString *cachPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory,NSUserDomainMask, YES) objectAtIndex:0];
NSArray *files = [[NSFileManager defaultManager] subpathsAtPath:cachPath];
NSLog(@"files :%d",[files count]);
for (NSString *p in files) {
NSError *error;
NSString *path = [cachPath stringByAppendingPathComponent:p];
if ([[NSFileManager defaultManager] fileExistsAtPath:path]) {
[[NSFileManager defaultManager] removeItemAtPath:path error:&error];
}
}
[self performSelectorOnMainThread:@selector(clearCacheSuccess) withObject:nilwaitUntilDone:YES];});
-(void)clearCacheSuccess
{
NSLog(@"清理成功");
}
6. 有些时候按钮按下去不希望,有黑色出现,就是说没有按钮动画,怎么办
[button setBackgroundImage: [UIIamge imageNamed:@"bfxq_btbg"] forState:UIControlStateHighlighted];
手指一直按着的时候就是UIControlStateHighlighted。
7.
This is where subclasses should create their custom view hierarchy if they aren't using a nib. Should never be called directly.
这是当他们没有正在使用nib视图页面,子类将会创建自己的自定义视图层。绝不能直接调用。
viewDidLoad;
Called after the view has been loaded. For view controllers created in code, this is after -loadView. For view controllers unarchived from a nib, this is after the view is set.
在视图加载后被调用,如果是在代码中创建的视图加载器,他将会在loadView方法后被调用,如果是从nib视图页面输出,他将会在视图设置好后后被调用。
Called when the view is about to made visible. Default does nothing
视图即将可见时调用。默认情况下不执行任何操作
viewDidAppear:
Called when the view has been fully transitioned onto the screen. Default does nothing
视图已完全过渡到屏幕上时调用
viewWillDisappear:
Called when the view is dismissed, covered or otherwise hidden. Default does nothing
视图被驳回时调用,覆盖或以其他方式隐藏。默认情况下不执行任何操作
viewDidDisappear:
Called after the view was dismissed, covered or otherwise hidden. Default does nothing
视图被驳回后调用,覆盖或以其他方式隐藏。默认情况下不执行任何操作
8. tableview 里面的cell想要选中,但还不想要选中效果
[cell setSelectionStyle: UITableViewCellSelectionStyleNone];
9 先看一段代码
OthersViewController *other = [[OthersViewController alloc] init];
other.title = @"个人中心";
[self.navigationController pushViewController:other animated:YES];
这个是很普通的界面跳转语句,可有的时候我们就是跳不过来,如下分析
有的时候我们想按一个按钮跳转界面,无奈我们的按钮是在局部界面,而上面的self.navigationController却是空的self.navigationController为神马会空呢?navigationController是UIViewController父类继承来的属性,不是随便都能用的,除非你当前viewController是被nav push进来的,或者用xib/代码做成navigationcontroller的root了,cocoa的代码应该是给赋值了。(题外话,我很多界面就是局部用了某个ViewController,这种情况该viewController的nav为空,如果要正确使用,可以从app取,可以自己赋值,可以整体界面取。。。想咋取都行)(转)http://lkjxshi.iteye.com/blog/1312213
解决办法就是,在这个局部的类中的文件里操作那个能跳转的界面的类
现在.h文件定义
@class A;
@interface B:UIViewController
@property(nonatomic,strong)A *a;
@end在.m文件定义
#import "A.h"
@synthesize a = _a;
...
<pre name="code" class="objc">[self.navigationController pushViewController:other animated:YES];
这里的@class相当于微薄的@,我觉得是调其本身,#import则是这个类型,但不是它本身。
看了书书上说就是@class创建一个前向引用。就是在告诉编译器:“相信我,以后你会知道这个类到底是什么,但是现在,你只需要知道这些。”
如果有循环依赖关系,@class也很有用。即A类使用B类,B累也使用A类。如果试图通过#import语句让这两个类相互引用,那么最后就会出现编译错误,但是如果在A.h中使用@class B,在B.h中使用@class A ,那么这两个类就可以相互引用了。
10. 小知识可真多,我们都知道tableview有几种style,有一种是group ,一种是plain,今天发现他们之间有个很搞笑的区别。
对于UITableView,我们可以通过代理方法:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
来为其某一个section添加一个header view。而当你向上滑动tableview时,会发现这个header view到了屏幕的顶部之后就不走了,而下面的table view还在继续向上滑动。
但是这个表必须是plain形式的,不能是group,别问我为什么,我从早上开始弄,现在太阳快落山了
11.
有时候用tableview的时候会发现加载的数据有些多,而我们恰恰想要完全显示出来,这里需要在加载文字的时候对原有的cell的高度进行扩容,直接操作是不可以的,需要将cell.frame付给一个CGRect的变量,把这个变量弄成我们想要的样子,然后再赋给cell.frame。特别要注意的是要将它的高和宽重写,我也不知道为什么这样,求大神解答。
12.
有时候会重复用一张图片,而这图片要求大小不一,且对其缩放影响忽略不计,那么可采取以下语句
CGSize size = CGSizeMake(16.5, 16.5);
[stopBt setTitle:@"全部开始" forState:UIControlStateNormal];
//改变图片尺寸,使之与暂停图片看齐
UIImage *a = [[UIImage alloc] init];
a = [UIImage imageNamed:@"ls_zt"];
UIGraphicsBeginImageContext(size);//size为我们所需要的图片尺寸
[a drawInRect:CGRectMake(0, 0, size.height, size.width)];//制定了图片绘制区域
a = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[stopBt setImage:a forState:UIControlStateNormal];
13.
我们常常会对空字符串进行判断如何判断呢?
字符串长度为0就可以了
if([String length]==0)
14.
对图片进行剪切,获取自己想要的区域,代码如下:
CGImageRef cgRef = portraitImg.CGImage; //这是图片的CGImageRef
CGImageRef imageRef = CGImageCreateWithImageInRect(cgRef, CGRectMake(0, portraitImg.size.height*0.221, portraitImg.size.width, portraitImg.size.height*0.557)); //对图片进行剪切,这里我就取原图的比例尺寸
UIImage *thumbScale = [UIImage imageWithCGImage:imageRef]; //将减下来的图片重新定义
CGImageRelease(imageRef);
portraitImg = thumbScale; //赋值
15.
对app 前去评分
NSString *evaluateString = [NSString stringWithFormat:@"itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=%@",nsAppId];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:evaluateString]];
这里的nsAppId就是app申请时给的appid
16.
获取今日,昨日字符串的方法
NSDate *today = [NSDate date];
NSDate *yesterday=[NSDate dateWithTimeIntervalSinceNow:-(24*60*60)];
NSDateFormatter *formatter = [[NSDateFormatter alloc ] init ];
[formatter setDateFormat:@"yyyy-MM-dd"];
todayTime = [formatter stringFromDate:today];
yestodayTime = [formatter stringFromDate:yesterday];
17.
字符串比对
[str2 isEqualToString:str1]
18.
判断版本
CGFloat statusBarHeight=0;
if ([[UIDevice currentDevice].systemVersion floatValue] >= 7.0)
{
statusBarHeight=20;
}
19.
A 对象 调用 B对象 的方法 。有两种实现手段 第一个是 B类中被实现的方法为“静态”方法, 首先在B的.h文件中,列出要实现的方法,用加号,像这样 +(void)getId, 然后依次.m文件中全部实现。 最后,A类要实现B类的方法的话,只需要引入B类头文件,调用方法时直接 使用“[类名 空格 方法名]” 即可 像这样 [B getId]. 第二种情况是,B类需要把被调用的方法要提前在h文件声明。 要使用的时候,在A类中实例化一个B类,像这样 : ObjectA *b = [ObjectB alloc] init],然后再向这个实例化对象发送消息调用方法就可以了 [b getId]
20.
在做APP时,我们会把有些数据放在plist文件里,切记不管放什么东西,里面不应该出现空的数据,特别要注意从后台拿来的数据。
本文来自博客园,作者:赫凯,转载请注明原文链接:https://www.cnblogs.com/heKaiii/p/15491362.html

浙公网安备 33010602011771号