【IT168技术】今天为iOS开发者奉献一份大餐,整理了iOS开发过程中的一些基础知识。首先,根据是Debug和Release显示不同的调试信息在Ios开发中是常见的,我以前是这么做的:
#ifdef DEBUG
#define Dlog NSLog
#else
#define Dlog //NSLog
#endif
但是在Xcode4.2 里当设置为release版本的时候,会给警告。
收集了下显示debug信息的方法
方法一
在prefix header pch文件中添加如下代码
#ifndef __OPTIMIZE__
# define NSLog(...) NSLog(__VA_ARGS__)
#else
# define NSLog(...) {}
#endif
方法二
// DLog is almost a drop-in replacement for NSLog
// DLog();
// DLog(@"here");
// DLog(@"value: %d", x);
// Unfortunately this doesn't work DLog(aStringVariable); you have to do this instead DLog(@"%@", aStringVariable);
#ifdef DEBUG
# define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
#else
# define DLog(...)
#endif
// ALog always displays output regardless of the DEBUG setting
#define ALog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
当然,你还想需要更强大的调试能力,那么这个开源的NSLogger可能会比较对你的口味。 https://github.com/fpillet/NSLogger
2.简要介绍下内存管理机制?
Cocoa中提供了一个机制来实现上面提到的这个逻辑模型,它被称为“引用计数”(referring counting)或“保留计数”(retain counting):
3.objc中的减号和加号的意思以及用法?
①减号表示一个函数、或者方法或者消息的开始(在一个类的实例上被调用和实施)(可以认为是私有方法)
②加号表示其他的函数可以直接调用这个类中的方法,而不用创建这个类的实例(俗称静态方法)
4、项目整理
按钮:
BtnWinWin = [UIButton buttonWithType: UIControlStateNormal];
BtnWinWin.frame = CGRectMake(768, 679, 256, 42);
[BtnWinWin setBackgroundImage:[UIImage imageNamed:@"btnwinwin.jpg"] forState:UIControlStateNormal];
[BtnWinWin addTarget:self action:@selector(WinWin) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:BtnWinWin];
播放器:
NSString *soundPath = [[NSBundle mainBundle]pathForResource:musicTop ofType:@"mp3"];
NSURL *soundURL = [[NSURL alloc]initFileURLWithPath:soundPath];
player = [[AVAudioPlayer alloc]initWithContentsOfURL:soundURL error:nil];
[player setDelegate:self];
[player play];
两个控制器之间的动画转换:
mainFrame = [[Test_Book1_2_Classes_ViewControlleralloc] init];
haveMainFram =TRUE;
CATransition *transition = [CATransitionanimation];
transition.duration = 1.0f; /* 间隔时间*/
transition.timingFunction = [CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionEaseInEaseOut]; /* 动画的开始与结束的快慢*/
transition.type = @"pageCurl";
transition.subtype = kCATransitionFromTop; /* 动画方向*/
transition.delegate = self;
[self.navigationController.view.layeraddAnimation:transition forKey:nil];
[self.navigationControllerpushViewController:mainFrameanimated:YES];
sdk相关:
1、两个.a静态库的合并,静态库有分适合模拟器的和真机的,如何合并请看:我的另一篇文章http://www.cnblogs.com/visen-0/archive/2011/08/02/2125067.html
2、创建root权限应用:http://www.cnblogs.com/visen-0/archive/2011/08/22/2149014.html
3、获取已经安装的列表:http://www.cnblogs.com/visen-0/archive/2011/08/22/2148847.html
4、自制.ipa文件下载安装。
5、判断是否越狱,去[NSFileManager defaultManager]找是否有对应的比如Cydia.app程序。
给服务器提交信息:
// 设备信息
UIDevice *device = [UIDevice currentDevice];
NSString *identifier = [[NSStringstringWithString:[device uniqueIdentifier]] lowercaseString];
NSLog(@"%@",identifier);
NSString *requestString = [NSStringstringWithFormat:@"http://www.yrwang.net/post.aspx?client=ios&deviceId=%@&reportMessage=%@",identifier,opinion.text];
NSString *requestStringUTF8 = [requestString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL * myURL = [[NSURL alloc] initWithString:requestStringUTF8];
NSMutableURLRequest *myRequest = [NSMutableURLRequestrequestWithURL: myURL
cachePolicy: NSURLRequestReloadIgnoringLocalAndRemoteCacheData
timeoutInterval: 30];
[myURL release];
connection_ = [[NSURLConnectionalloc] initWithRequest: myRequest delegate: self];
解析xml:
NSXMLParser* xmlRead = [[NSXMLParser alloc] initWithData:data];//初始化NSXMLParser对象
[data release];
[xmlRead setDelegate:self];
[xmlRead parse];
监听者模式:
[[NSNotificationCenterdefaultCenter] addObserver:self
selector:@selector(getUpdatedPoints:)
name:111
object:nil];
[[NSNotificationCenterdefaultCenter] postNotificationName:111 object:nil];
单例模式:
static AdPublisherConnect *sharedInstance_ = nil;
+ (AdPublisherConnect*)sharedAdPublisherConnect
{
if(!sharedInstance_)
{
sharedInstance_ = [[superalloc] init];
}
returnsharedInstance_;
}
文件的读取写,创建:
这个是创建的例子:
//创建文件管理器
NSFileManager *fileManager = [NSFileManagerdefaultManager];
//获取路径
//参数NSDocumentDirectory要获取那种路径
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];//去处需要的路径
//更改到待操作的目录下
[fileManager changeCurrentDirectoryPath:[documentsDirectory stringByExpandingTildeInPath]];
//创建文件fileName文件名称,contents文件的内容,如果开始没有内容可以设置为nil,attributes文件的属性,初始为nil
//获取文件路径
NSString *path = [documentsDirectory stringByAppendingPathComponent:fileName];
//创建数据缓冲
NSMutableData *writer = [[NSMutableDataalloc] init];
//将字符串添加到缓冲中
[writer appendData:[contents dataUsingEncoding:NSUTF8StringEncoding]];
//将其他数据添加到缓冲中
//将缓冲的数据写入到文件中
[writer writeToFile:path atomically:YES];
[writer release];
字符串的获取某个操作:NSRange
e = [tempString rangeOfString:@","];
key = [tempString substringToIndex:e.location];
e = [tempString rangeOfString:@"\r\n"];
tempString = [tempString substringFromIndex:e.location+1];
录音:
AVAudioSession
分页:
uitable分页
查找文件目录;
+ (NSMutableArray *)findFile{
NSFileManager *fileManager = [[NSFileManager defaultManager] init];
NSMutableArray *everyTitle = [[NSMutableArray alloc] init];
NSArray *filePaths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
NSString *filePath = [filePaths objectAtIndex:0];
NSLog(@"%@",filePath);
NSDirectoryEnumerator *direnum = [fileManager enumeratorAtPath:filePath];
NSString *fileName;
while ((fileName = [direnum nextObject])) {
[everyTitle addObject:fileName];
}
return everyTitle;
}
表单:
UIActionSheet
长按按钮:
UILongPressGestureRecognizer
滚动视图:
UIScrollView
web网页:
UIWebView
隐藏导航栏,应用全屏。