iphone開發零碎知識彙總

安迪潘發表於2011-11-03

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模擬器相簿裡新增圖片方法:

從電腦裡直接向模擬器拖一張圖片,左鍵長按,儲存即可

相關文章