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

常用 IPHONE 编程 基础代码

 2010-03-10 16:08:00 来源:WEB开发网   
核心提示:NSString *path = [documentsDirectoryPath stringByAppendingPathComponent:@"myApp.plist"];NSMutableDictionary *plist = [NSDictionary dictionaryWithConte

NSString *path = [documentsDirectoryPath stringByAppendingPathComponent:@"myApp.plist"];

NSMutableDictionary *plist = [NSDictionary dictionaryWithContentsOfFile: path];

Now read and set key/values

myKey = (int)[[plist valueForKey:@"myKey"] intValue];

myKey2 = (bool)[[plist valueForKey:@"myKey2"] boolValue];

[plist setValue:myKey forKey:@"myKey"];

[plist writeToFile:path atomically:YES];

Alerts

Show a simple alert with OK button.

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:

@"An Alert!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];

[alert show];

[alert release];

Info button

Increase the touchable area on the Info button, so it's easier to press.

CGRect newInfoButtonRect = CGRectMake(infoButton.frame.origin.x-25, infoButton.frame.origin.y-25, infoButton.frame.size.width+50, infoButton.frame.size.height+50);

[infoButton setFrame:newInfoButtonRect];

Detecting Subviews

You can loop through subviews of an existing view. This works especially well if you use the "tag" property on your views.

for (UIImageView *anImage in [self.view subviews])

{

if (anImage.tag == 1)

{ // do something }

}

上一页  1 2 3 4 5 

Tags:常用 IPHONE 编程

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