1、IOS Url Encode(POST上传的时候,汉字上传的格式为%AE这种形式),可以通过下面方法进行转换。
-(NSString*)UrlValueEncode:(NSString*)str
{
NSString *result = (NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,(CFStringRef)str, NULL,CFSTR("!*'();:@&=+$,/?%#[]"),kCFStringEncodingUTF8));
[result autorelease];
NSLog(@"%@",result);
return result;
}
2、键盘上面View在改变键盘类型的时候,View的frame值实时改变,可以使用通知中心来进行观察,实时的改变View的frame。[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChangeFrame:) name:UIKeyboardWillChangeFrameNotification object:nil];也可以设置键盘的inputView。
3、在解析网络返回数据的时候,接收数据类型不匹配,比如:比如说返回的是NSNumber,接收用NSString。
4、数组越界的问题(常见情况是:先进行网络请求的语句,但是在下面语句紧接着就使用了接收网络数据的NSArray或者是NSMutableArray),对一个元素个数为0的数组进行objectAtIndex:操作,导致数组越界,解决方法是在从数组中取元素的时候,对数组进行[array count]判断;保证数组中元素个数不为0,然后再对数组进行操作。
5、网络返回数据为
6、从网上下载的demo,在参照demo自己写的时候,莫名其妙的出现崩溃的情况,一般情况下都是,网上的Demo使用的时ARC,但是学生在自己工程里面使用的时MRC,导致某些对象提前释放。解决方法,在TARGETS-Build Phases-Compile Sources 对应的.m文件添加-fobjc-arc。如果想让某个类不使用ARC那么可以在TARGETS-Build Phases-Compile Sources 对应的.m文件添加-fno-objc-arc。
7、在IOS7中UINavigationController中使用UITextView或者UIScrollView的时候,文本的对齐方式,垂直方向的对齐方式是居中对齐,不是上对齐,需要在viewDidlLoad里面添加:
automaticallyAdjustsScrollViewInsets
if([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0){
self.automaticallyAdjustsScrollViewInsets = NO; // Avoid the top UITextView space, iOS7 (~bug?)
}
在使用UIScrollView的时候也会出现偏移。
8、在使用UICollectionView的时候,崩溃出现'UICollectionView must be initialized with a non-nil layout parameter’,原因是没有进行UICollectionViewFlowLayout的初始化。
解决方法:
UICollectionViewFlowLayout *layout= [[UICollectionViewFlowLayout alloc]init];
self.collectionView = [[UICollectionView alloc]initWithFrame:self.view.bounds collectionViewLayout:layout];
[self.view addSubView:self.collectionView];
[self.collectionView registerClass:[UICollectionViewCell class]
forCellWithReuseIdentifier:@"Cell"];
self.collectionView.delegate=self;
self.collectionView.dataSource=self;
注意出现:delegate,dataSource协议的时候
self.collectionView.delegate=self;
self.collectionView.dataSource=self;
对应的在.h里面一定要加:
9、在导入CocoaHTTPServer框架的时候,在已经导入libxml2的情况下,设置了header search path为${SDCROOT}/usr/include/libxml2,仍出现unknown type name ‘xmlNodePtr’等20个错误,原因是libxml2在其他文件夹里面(比如在cocos2d-x的文件夹里面),另外导入libxml2类似框架的时候是在TARGETS-Build Phases-Link Binary With Libraries,而不是在*Tests下。
10、在一个试图模态除一个试图的时候,出现Presenting view controllers on detached view controllers is discouraged <*>,解决方法:
[self.view.window.rootViewController presentViewController:viewController animated:YES completion:nil];
11、程序运行的过程中出现’Only run on the main thread!’,是因为更新UI不是在主线程进行的。
12、UITableViewCell的在IOS5和IOS6有不同的初始化方法,在IOS6中采用- (id)dequeueReusableCellWithIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath对UITableViewCell进行初始化时,需要使用配套的- (void)registerClass:(Class)cellClass forCellReuseIdentifier:(NSString *)identifier方法对UITableViewCell进行注册。
13、在使用百度地图API的时候,先需要在appDelegate里面设置百度地图的代理,不然进入主屏幕之后是黑色的。
14、在使用UITableView的时候,section会停留在屏幕的最上方,直到滑动到下一个分区,解决方法,tableView的样式选用group,然后自定义headerView。
15、涉及到网络请求和UITableView结合展示数据的时候,出现数组越界问题,原因是:网络请求还没有完成,但是在UITableView的代理方法里面已经开始使用数组(对一个元素个数为0的数组调用objectAtIndex:方法),解决方法是在使用数组的时候判断数组中元素个数,不为0才进行操作。
16、在使用第三方抽屉效果(DDMenu)的过程中,如果从Center试图Push到下级ViewCOntroller(AViewController),那么在AViewController中使用手势仍可以返回DDMenu的左视图,如果想取消这个效果,那么可以在AViewController中把DDMenu的手势暂时关闭。
17、如果对一个数组使用系统的copy,那么copy得到的数组是个不可变的数组。
8、在类的.h里面,如果在#import
19、在使用本地通知的时候,如果注册过通知,但是把程序删除之后,再次安装的时候,会出现两次通知提醒(因为这些通知加入到系统里面)。解决方案是在进入程序时把之前的通知删除掉。
20、在UITableViewCell中动态展示数据的时候,可以在自定义Cell里面写一个类方法来专门计算Cell的高度。
21、 UITableView 定位到某个分区或者某一行
NSIndexPath *scrollIndexPath = [NSIndexPath indexPathForRow:0 inSection:3];
[_tableView scrollToRowAtIndexPath:scrollIndexPath
atScrollPosition:UITableViewScrollPositionTop animated:YES];
22、在做视频播放和下载的时候出现这个错误RTCReporting: resolve from https://qtpartners.apple.com/storebags/hls?version=4.10,解决方案(换台机器或者换个Xcode就可以)
。网上找的相似的错误给出的解决方案是:1、This seems to be a problem with trying to play videos on the simulator. I've had this problem for months now, and just ran into it again today when I was trying to play video on my simulator.
The solution, while not great, is to use an actual device instead of the simulator for testing video playing.
2、You need use:
[player play];
after you sound play in the real device and in simulator.
23、IOS7状态栏的适配问题http://beyondvincent.com/blog/2013/11/03/120-customize-navigation-status-bar-ios-7/
24、完整的单例模式,需要重写retain、release、autorelease、retainCount等方法.相关介绍http://beyondvincent.com/blog/2013/05/09/20/,https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CocoaFundamentals/CocoaObjects/CocoaObjects.html
25、ShareSDK真机出现Undefined symbols for architecture arm64: "_OBJC_CLASS_$_WeiboApi", referenced from: objc-class-ref in MMAppDelegate.o,解决方法http://blog.csdn.net/topbar/article/details/21449643
26、如果你的应用程序是从别人那边拷贝过来的,如果提示第三方开源框架使用错误或者找不到,那么把第三方开源框架重新导入一遍有时就可以了