2011年3月31日 星期四

由init、loadView、viewDidLoad、viewDidUnload、dealloc的關係說起

http://www.cnblogs.com/wwwkhd/archive/2011/03/14/1983192.html

由init、loadView、viewDidLoad、viewDidUnload、dealloc的關係說起

[轉] iphone程序啟動互相調用


http://www.cnblogs.com/wwwkhd/archive/2011/03/25/1995830.html

如何點擊一個程序調用起來另一個程序的方法 調用程序A 被調用程序B A中要設置一些調用的信息

iPhone 內存管理(轉)


copy 和retain 的區別

【轉】 【iPhone】UIImagePickerController 查看圖片,視頻,錄像


轉載自 hh20040410
最終編輯 hh20040410
UIImagePickerController -- the only sanctioned way to get videos/movies or images/pictures on supported devices UIImagePickerController

2011年3月30日 星期三

Save image to photo library on simulator

The path in which all the photos saved is:

/Users/USERNAME/Library/Application Support/iPhone Simulator/4.1/Media

4.1 or which sdk you are using

So the easiest way is to drag and drop a image on the simulator. The Simulator will open a webpage to your local file ("file://…") and then you can save it but holding your mouse key for 3 seconds or so. Then click "save image" and it should appear in your Photo Library.

2011年3月23日 星期三

Adam Lambert - For Your Entertainment

ADAM LAMBERT - Whataya Want From Me

Travie McCoy: Billionaire

Adele - Rolling In The Deep

There's a fire starting in my heart Reaching a fever pitch, it's bringing me out the dark Finally I can see you crystal clear Go head and sell me out and I'll lay your shit bare See how I leave with every piece of you Don't underestimate the things that I will do There's a fire starting in my heart Reaching a fever pitch And its bring me out the dark The scars of your love remind me of us They keep me thinking that we almost had it all The scars of your love they leave me breathless I can't help feeling We could have had it all Rolling in the deep You had my heart inside of your hand And you played it To the beat Baby, I have no story to be told But I've heard one on you And I'm gonna make your head burn Think of me in the depths of your despair Making a home down there As mine sure won't be shared The scars of your love remind me of us They keep me thinking that we almost had it all The scars of your love they leave me breathless I can't help feeling We could have had it all Rolling in the deep You had my heart inside of your hand And you played it To the beat Throw your soul through every open door Count your blessings to find what you look for Turned my sorrow into treasured gold You pay me back in kind and reap just what you sow We could have had it all We could have had it all It all, it all it all, We could have had it all Rolling in the deep You had my heart inside of your hand And you played it To the beat

2011年3月16日 星期三

JingJong's Blog: iPhone 自訂navigation bar全攻略 包含按鈕,高度及圖片背景

JingJong's Blog
iPhone的UI真的有很多小細節,我想也累積一些東西了就po上來吧. 自製化的navigation bar到底有多彈性呢? 
我想改變navigation bar上面按鈕的樣式,可以! 
想改變navigation bar的高度,可以! 
想給navigation bar上個圖片,可以! 
那navigation bar上按鈕的位置呢? 還是可以!!


如果技巧太鼈三就包涵一下啦:P 
navigation bar中的按鈕參照UIBarButtonItemStyle所定義項目少了custom這項 不過可以透過initWithCustomView的方式建立自訂的按鈕 詳細作法如下: 
1. 先建立一個UIButton,設定其大小位置以及各狀態對應的圖片,最後還要一個action的指向 


UIButton * fooButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
fooButton.bounds = CGRectMake(0, 0, 40.0, 40.0); 
[fooButton setImage:[UIImage imageNamed:@"foo.png"] forState:UIControlStateNormal]; 
[fooButton addTarget:self action:@selector(fooFired:) forControlEvents:UIControlEventTouchUpInside]; 

2. 接著new一個UIBarButtonItem後,加入navigationItem(這邊以右邊為例) 


UIBarButtonItem *fooBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:fooButton];  

self.navigationItem.rightBarButtonItem = fooBarButtonItem;  
[fooBarButtonItem release]; 


(trick 1) 接下來講講navigation bar的高度怎麼改變, 網路上可以找到一些方法,不過直接改變高度似乎不可行(至少我自己試過不行) self.navigationController.navigationBar.frame.size.height 另外一個就正常啦,set自己想要的大小位置 [


self.navigationController.navigationBar setFrame:CGRectMake(0, 0, self.view.width, height)];


 (trick 2) 給navigation bar上個圖片也不會太難 
1. 首先new一個UIImageView 
UIImageView * banner = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, width, height)];

2. 指定這個ImageView載入的圖片
banner.image = [UIImage imageNamed:@"banner.png"];  


3. 透過addsubview的方式加進navigation bar(這裡額外指定layer在最底層) [self.navigationController.navigationBar insertSubview:banner atIndex:0];  


咳~醜媳婦終究還是要見公婆 改變navigation bar按鈕位置的方法有點投機 如果想要達到下圖的樣子要善用trick1跟trick2


首先在我們改變navigation bar高度的過程中 一定會發現按鈕的位置都偏下,就像下面的圖

沒關係,我們在navigation bar上面放一個高度較高,size較大的圖片蓋過去
如此一來navigation bar上面的按鈕怎麼看都會在中間啦!

順帶一提:自訂的navigation bar剛開始跑起來都還好端端的,但是隱藏過後又要顯示時,按鈕設定全跑了,navigation bar高度也會回復預設值.後來解決的方法還滿暴力的,就是要再度顯示之前,再設定一次navigation bar的frame size

[self.navigationController.navigationBar setFrame:CGRectMake(0, 0, width, height)];
[self.navigationController setNavigationBarHidden:NO animated:NO];

Update:

如果rotate會導致navigation bar上面的button位置跑掉,表示其高度被設定回預設值,
解決的方法也是在rotate完成後,再設定一次navigation bar的frame size

(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation 
{
//set your frame size here
}


參考資料:stackoverflow - bar height

JingJong's Blog: iPhone 更改專案名稱

JingJong's Blog
剛起始一個專案的時候 我有個很糟糕的習慣就是取了爛名字 什麼xxxtest阿,xxxdemo等等... 等真的要release的時候不免被人家念一頓 其實要修改 project name也不難 1. 找到專案的info.plist 2. 找到"Bundle display name"的欄位 3. 將原本 ${PRODUCT_NAME} 改成想要的名稱 如果遇到 the program being debugged is not being run 的error message也不要慌, shift + command + K 把專案給clean重編就好了 參考資料:stackoverflow iphonedevsdk

2011年3月15日 星期二

2011年3月14日 星期一

建立多Header的Table

NSArray* tableIndex;

- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView

{

return tableIndex;

}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{

switch (section) {

case 0:

return @"JPG";

break;

case 1:

return @"PDF";

break;

case 2:

return @"PNG";

break;

case 3:

return @"Excel";

break;

case 4:

return @"Word";

break;

case 5:

return @"Power Point";

break;

case 6:

return @"TIF";

break;

case 7:

return @"BMP";

break;

case 8:

return @"M4V";

break;

}

return nil;

}

UITable 更新

- (void)viewWillAppear:(BOOL)animated {

[self.table reloadData];

}

從document取得某類型檔案

fileListJPG = [[NSMutableArray alloc] init];

fileListJPG = [[[[NSFileManager defaultManager] directoryContentsAtPath:DOCUMENTS_FOLDER]

pathsMatchingExtensions:[NSArray arrayWithObject:@"jpg"]] retain];

複製檔案到document folder

NSFileManager *fileManager = [NSFileManager defaultManager];

[fileManager copyItemAtPath:resourcePath toPath:documentPath error:nil];

取得"Resources"資料夾路徑

NSFileManager *fileManager = [NSFileManager defaultManager];

// ex: *.JPG

NSString *resourceTestJPG = [[[NSBundle mainBundle] resourcePath]

stringByAppendingPathComponent:@"Test.jpg"];

2011年3月13日 星期日

取得Documents Folder

1.

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

NSString * DOCUMENTS_FOLDER = [paths objectAtIndex:0];

2

#define DOCUMENTS_FOLDER [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]

3

path = [DOCUMENTS_FOLDER stringByAppendingPathComponent:selectedFileNameObject];;