将图片写入模拟器相册
UIImageWriteToSavedPhotosAlbum([UIImage imageNamed:@"call"], nil, nil, nil);
UIView* uiViewBuildingAddress=[[UIViewalloc]initWithFrame:self.view.frame];
uiViewBuildingAddress.backgroundColor=[UIColorblackColor];
//父视图不影响子视图背景色
uiViewBuildingAddress.backgroundColor=[UIColorcolorWithWhite:0
alpha:0.6];
#pragma mark - 获取view从属的viewController
- (UIViewController*)getViewController
{
for (UIView* next = [selfsuperview]; next; next = next.superview)
{
UIResponder* nextResponder = [next nextResponder];
if ([nextResponderisKindOfClass:[UIViewControllerclass]])
{
return (UIViewController*)nextResponder;
}
}
return nil;
}
- (UIViewController*)getViewController
{
while ([[self nextResponder] isKindOfClass:[UIViewController class]])
{
return (UIViewController*)[self nextResponder];
}
return nil;
}
避免Block的Retain Cycle
1. __block ASIHTTPRequest* request=[ASIHTTPRequestrequestWithURL:url];
__weak ASIHTTPRequest* request2=request;
2. ASIHTTPRequest* request=[ASIHTTPRequestrequestWithURL:url];
ASIHTTPRequest* __weak request2=request;
#pragma mark - 返回当前时间精确到秒作为图片名
NSDateFormatter * formatter = [[NSDateFormatter alloc ] init];
//[formatter setDateFormat:@"YYYY.MM.dd.hh.mm.ss"];//秒
// [formatter setDateFormat:@"YYYY-MM-dd hh:mm:ss:SSS"];//毫秒
[formatter setDateFormat:@"YYYYMMddhhmmssSSS"];
NSString* nsStringCurrentTime = [formatter stringFromDate:[NSDate date]];
// NSLog(@"当前时间:%@", nsStringCurrentTime);
两个类之间用数据类属性传值,传值失败,检查发现,接收类的数据存储类(nsArray/nsString...........)开辟了新的内存,导致失败;
用XIB搭建uiTextField时取消键盘失效
-(BOOL)textFieldShouldReturn:(UITextField *)textField
失效,代码也写好了delegate的,解决办法是双重保险,XIB文件的代理连线也需要检查。都有就OK了。
获取控件相对于屏幕的方法
CGRect cgrect= [textField convertRect:textField.frame
toView:self.superview.superview];
属性化字符串的使用
效果如右图,开始时无法用lenght取到冒号后面的nsRange,老说超出范围;后来一想前面肯定0开始的,所以,直接先将字体设置为橘色,然后取前面的文字还原颜色就好了。
Google后明白,为什么提示超出范围了,应为range代表的是,起点以及从起点开始的长度范围,并不是字符串的整体长度;
uiTextView遮挡键盘的处理
获取设备此存及物理分辨率
NSString* height = [NSString stringWithFormat:@"%d", (NSInteger)[UIScreen mainScreen].currentMode.size.height];
NSString* width = [NSString stringWithFormat:@"%d", (NSInteger)[UIScreen mainScreen].currentMode.size.width];
#define CgrectUIScreen [UIScreen mainScreen].bounds
#define UIScreenWide [UIScreen mainScreen].bounds.size.width
#define UIScreenHeight [UIScreen mainScreen].bounds.size.height
屏蔽NSLog
#define NSLog(...) {};
#endif
获取UItableView的某个Cell,千万注意红色的部分,不要用self直接调用方法(不要问LZ为什么),是用UITableView的实例来调用的
长按手势的判定,防止出现两次
修改UITextField的LAYER层时注意需要注意需要取消BorderStyle否则无效
#pragma mark - 如无必要不要重载视图的生命周期方法,即使写出来什么代码都没添加
比如viewWillAppear,loadView........否则可能引发严重的BUG
加载WEBView的拨号
地图中两个经纬度间的距离
经高德经纬度测试误差±500m,其他未测
NSString转NSDictionary
uitabeleviewCell添加了uitextfield无法呼出键盘,在模拟器的工具栏找到如下选项,尝试去掉第二选项(连接硬件键盘)
使用高德地图API时提示“apiKey为空...”
[MAMapServices sharedServices].apiKey=MAMapKey; 进入此方法 显示提示
+ (MAMapServices *)sharedServices;
/*!
@brief API Key, 在创建MAMapView之前需要先绑定key.
*/
@property (nonatomic, copy) NSString *apiKey;
确保绑定apiKey写在第一位位置即可。
打印应用的缓存路径
NSString *path = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
NSLog(@"path:%@",path);
storyBoard代码跳转
1.通过storyBoard里已有的segue,设置segue的Identifier.
[self performSegueWithIdentifier:@"SegueName" sender:self];
2.通过storyBoard里设置storyBoardID.
UIStoryboard* uiStoryboardMain=[UIStoryboard storyboardWithName:@"StoryboardMain"
bundle:nil];
UIViewController* uiViewController=[uiStoryboardMain instantiateViewControllerWithIdentifier:@"tabBarController"];
[self presentViewController:uiViewController
animated:YES
completion:^
{
}];
使用地理编码时,打印的数据是:Name = "2nd Ring Road Elevated Road Yulin Residential District Wuhou Chengdu Sichuan China";明显的是英式翻译,那么就是本地化的问题,google后得知,应该将模拟器设置为中文语言就没有问题了。 Name = "\U822a\U7a7a\U8def";但是需要纠正偏差才准确。
-(void)locationManager:(CLLocationManager *)manager
didUpdateLocations:(NSArray *)locations
{
if (locations.count>0)
{
CLLocation* latesLocation=[locations lastObject];
// NSLog(@"latesLocation:%@",latesLocation);
// mapCenter(latesLocation.coordinate);
CLGeocoder* geocoder=[[CLGeocoder alloc]init];
[geocoder reverseGeocodeLocation:latesLocation
completionHandler:^(NSArray *placemarks, NSError *error)
{
if (placemarks.count>0)
{
CLPlacemark* latesPlaceMark=(CLPlacemark*)[placemarks lastObject];
NSLog(@"latesPlaceMark.addressDictionary:%@",(latesPlaceMark.addressDictionary[@"FormattedAddressLines"])[0]);
}
}];
}
}