iOS开发笔记-3
关于Masonry包
是#import <Masonry.h>
不是#import "Masonry.h"
设置section之间的背景颜色
1 2 3 4
| - (void)tableView:(UITableView *)tableView willDisplayFooterView:(UIView *)view forSection:(NSInteger)section {
view.tintColor = kThemeHomePageBackgroundColor; }
|
cell.accessoryView 无法获取
在写cell的页面的时候,使用了系统自带右侧的箭头的cell格式:
cell.accessoryType=UITableViewCellAccessoryNone;
然后如下图所示,想在右侧箭头左边加label,在使用Masonry相对布局获取accessoryView的mas_left的时候获取不到,其他属性也获取不到。不知道什么原因。准备去stackoverflow问一下,如果得到了回答就把答案更新到这里。
本地存取
- 取:
[[NSUserDefaults standardUserDefaults] boolForKey:bool键];
[[NSUserDefaults standardUserDefaults] stringForKey:键];
- 存:
[[NSUserDefaults standardUserDefaults] setBool:bool值 forKey:bool键];
[[NSUserDefaults standardUserDefaults] setValue:值 forKey:键];
不是用[button.title.label setTextColor...];
而是用[button setTitleColor:[UIColor yellowColor] forState:UIControlStateNormal];
设置让tableviewL里面的某个cell不可选中
cell.selectionStyle = NO;
数据库操作时遇到的问题
之前写数据库的时候,新建了一个表,可以正常增删改查。后来觉得表的某一列的列名起的不好,于是在代码中把列名改了,然后就不能正常操作数据库了。这时候应该去sqlite中把表删除(或者直接卸载掉APP)然后让程序重新建表就可以了。
截取字符串
1 2 3 4
| NSLog(@"%@",[str substringFromIndex:2]); NSLog(@"%@",[str substringToIndex:5]); NSLog(@"%@",[str substringWithRange:NSMakeRange(2, 3)]); NSArray *arry=[str componentsSeparatedByString:@"="];
|
显示网络图片
1 2 3 4 5 6 7 8 9 10 11 12
| + (UIImage *)loadImage { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; UIImage *image = [[UIImage alloc] initWithContentsOfFile:[[documentsDirectory stringByAppendingString:@"/image"] stringByAppendingString:@"/default.png"]]; if (image) { return image; }else{ return [UIImage imageNamed:@"image"]; } return image; }
|
iOS时间戳
其实项目并没有用到,就直接抄的网上的,回头好好研究~
1 2 3 4 5 6
| NSString* timeStr = @"2011-01-26 17:40:50"; NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease]; [formatter setDateStyle:NSDateFormatterMediumStyle]; [formatter setTimeStyle:NSDateFormatterShortStyle]; [formatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
|
1 2 3 4 5 6
| NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"Asia/Shanghai"]; [formatter setTimeZone:timeZone]; NSDate* date = [formatter dateFromString:timeStr]; NSDate *datenow = [NSDate date]; NSString *nowtimeStr = [formatter stringFromDate:datenow];
|
1 2 3
| NSString *timeSp = [NSString stringWithFormat:@"%d", (long)[datenow timeIntervalSince1970]]; NSLog(@"timeSp:%@",timeSp);
|
1 2 3 4 5 6 7 8 9 10 11 12 13
| NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:1296035591]; NSLog(@"1296035591 = %@",confromTimesp); NSString *confromTimespStr = [formatter stringFromDate:confromTimesp]; NSLog(@"confromTimespStr = %@",confromTimespStr);
NSDateFormatter* formatter = [[NSDateFormatter alloc] init]; [formatter setDateStyle:NSDateFormatterMediumStyle]; [formatter setTimeStyle:NSDateFormatterShortStyle]; [formatter setDateFormat:@"yyyyMMddHHMMss"]; NSDate *date = [formatter dateFromString:@"1283376197"]; NSLog(@"date1:%@",date); [formatter release];
|