WEB开发网
开发学院手机开发iPhone 开发 常用 IPHONE 编程 基础代码 阅读

常用 IPHONE 编程 基础代码

 2010-03-10 16:08:00 来源:WEB开发网   
核心提示:performSelectorOnMainThread.[self performSelectorOnMainThread:@selector(myMethod) withObject:nil waitUntilDone:false];TimersThis timer will call myMethod every
performSelectorOnMainThread.

[self performSelectorOnMainThread:@selector(myMethod) withObject:nil waitUntilDone:false];

Timers

This timer will call myMethod every 1 second.

[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(myMethod) userInfo:nil repeats:YES];

2. Then pass the NSTimer object to your method:

-(void)myMethod:(NSTimer*)timer

{

// Now I can access all the properties and methods of myObject

[[timer userInfo] myObjectMethod];

}

3.To stop a timer, use "invalidate":

[myTimer invalidate]; myTimer = nil; // ensures we never invalidate an already invalid Timer

Plist files

Application-specific plist files can be stored in the Resources folder of the app bundle. When the app first launches, it should check if there is an existing plist in the user's Documents folder, and if not it should copy the plist from the app bundle.

// Look in Documents for an existing plist file

NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES);

NSString *documentsDirectory = [paths objectAtIndex:0];

myPlistPath = [documentsDirectory stringByAppendingPathComponent:

[NSString stringWithFormat: @"%@.plist", plistName] ];

[myPlistPath retain];

// If it's not there, copy it from the bundle

NSFileManager *fileManger = [NSFileManager defaultManager];

if ( ![fileManger fileExistsAtPath:myPlistPath] )

{

NSString *pathToSettingsInBundle = [[NSBundle mainBundle] pathForResource:plistName ofType:@"plist"];

}

Now read the plist file from Documents

NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES);

NSString *documentsDirectoryPath = [paths objectAtIndex:0];

上一页  1 2 3 4 5  下一页

Tags:常用 IPHONE 编程

编辑录入:coldstar [复制链接] [打 印]
赞助商链接