天天看点

iphone开发零碎知识汇总

1.xcode编译项目缓存路径:

~/Library/Developer/Xcode/DerivedData/'ProjectName-'+'randomcharacters'/Build/

2.iphone开发 地图线路

参考文章:http://hi.baidu.com/yunhuaikong/blog/item/02718e4fa46878d0d0c86a6b.html

3.代码添加UITab bar的图片文字

NSInteger index = 0;

while(index < 4){ // 4 is the number of tabbar items

        UINavigationController *navCtrlr = (UINavigationController*)[[tabBarController viewControllers] objectAtIndex:index];

        UITabBarItem *tabBar = (UITabBarItem *) navCtrlr.tabBarItem;

        if(index == 0){

        tabBar.image = [UIImage imageNamed:@"home-item.png"];

        tabBar.title = @"home";

    }

        ...

        index ++;

}
           

4.用代码向已有的UIViewController中添加UINavigationController

MyExampleViewController *vc = [[[MyExampleViewController alloc] initWithNibName:@"MyExample" bundle:nil] autorelease];
UINavigationController *navController = [[[UINavigationController alloc] initWithRootViewController:vc] autorelease];
[self presentModalViewController:navController animated:YES];
           

5.多个字符串连接

NSString* string; // 结果字符串

NSString* string1, string2; //已存在的字符串

1. string = [NSString initWithFormat:@"%@,%@", string1, string2 ];

2. string = [string1 stringByAppendingString:string2];

3 . string = [string stringByAppendingFormat:@"%@,%@",string1, string2];

这三种方法都会将string1和string2 合并,但是第二个方法更有效率

6.向iphone模拟器相册里添加图片方法:

从电脑里直接向模拟器拖一张图片,左键长按,保存即可