IOS 问题集锦

问题一

Tag: NSUserDefaults NSDictionary NSMutableDictionary
You should know:
You can only store things like NSArray,NSDictionary, NSString, NSData, NSNumber, and NSDate in `NSUserDefaults.

我将一个用户的信息以NSDictionary形式放在NSUserDefaults。当需要对用户信息进行更新时,首先将NSDictionary转换成NSMutableDictionary,因为NSDictionary是不能更改的对象,
对NSMutableDictionary进行更新,然后将NSMutableDictionary保存到NSUserDefaults。
注意,NSMutableDictionary是NSDictionary的子类,所以也可以保存,保存后就不可修改啦。

NSDictionary * userDic = [self getUser];
NSMutableDictionary *muserDic = [userDic mutableCopy];
[muserDic setValue:name forKey:@"name"];
[self setUser:muserDic];


问题二

Tag: Segue View Controller Navigation Controller 跳转

segue 跳转                                    动画效果:上下切换
可跳转对象:navigationcontroller & viewcontroller
跳:[self performSegueWithIdentifier:@"loginSegue" sender:self];
回:[self dismissModalViewControllerAnimated:YES];

view controllers 跳转
1) pushviewcontroller                   动画效果:左右切换
原理:往NavigationController里面压入view controller  
可跳转对象:viewcontroller
跳:[self.navigationController pushViewController:ViewController animated:YES];
回:[self.navigationController popToRootViewControllerAnimated:YES];
回:[self.navigationController popViewControllerAnimated:TRUE];
注意:这里往navigationcontroller里面压viewcontroller,如果压navigationcontroller,则报错
'Pushing a navigation controller is not supported'


2) presentViewController              动画效果:上下切换
原理:临时弹出一个navigationcontroller或者viewcontroller收集用户信息
可跳转对象:navigationcontroller & viewcontroller                 
跳:[self presentViewController:[self.storyboard instantiateViewControllerWithIdentifier:@"SkJdHistorySI"] animated:YES completion:nil];
回:[self dismissViewControllerAnimated:YES completion:nil];

3) presentModalViewController     动画效果:左右切换
可跳转对象:navigationcontroller & viewcontroller   
跳:[self.navigationController presentModalViewController:nav animated:YES];
回:[self dismissModalViewControllerAnimated:TRUE];

问题三:
View controllers 之间是如何传递参数
http://www.cnblogs.com/likwo/archive/2011/03/02/1968785.html
segue传递参数也很方便

问题四:
Http Return Nil
Bad URL Error With NSURLRequest
http://stackoverflow.com/questions/11362153/bad-url-error-with-nsurlrequest

问题五:
iOS中如何实现TextView仅可粘贴不可输入的功能
http://my.oschina.net/u/728866/blog/156763

猜你喜欢

转载自menuz.iteye.com/blog/2017172