NSIndexPath *temp_IndexPath = [NSIndexPath indexPathForRow:lastIndexPath_row inSection:lastIndexPath_section];
其中lastIndexPath_row, lastIndexPath_section.形態為NSInteger
主要是為了讓UITableView做edit有彈跳視窗所使用的
Translate
2012年12月26日 星期三
2012年12月20日 星期四
navigationBar setBackgroundImage
[naVC.navigationBar setBackgroundImage:[UIImage imageNamed:@"menubar.png"] forBarMetrics:UIBarMetricsDefault];
2012年12月19日 星期三
Xcode4.2 本地化多國語言Localizable跟AppleLanguages
1.再Supporting Files文件夾點右鍵,New File->iOS->Resource->Strings File取名為Localizable
2.選中Localizable.strings 再回Xcode->View->Utilites->File Inspector,再Localization中點擊+添加語言 比如中文英文日文
3.
Localizable.strings(English)
"test"=test";
Localizable.strings(Chinese)
"test="測試";
4.使用方法
[temp_lab setText:NSLocalizedString(@"test", @"測試用的")];
誇號裡第一個參數是要顯示的內容,與個Localozable.strings中的id對應
第二個參數是對第一個參數的註解,一般可以為空字串
另外也可以用程式取得使用者的語系
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSArray *languages = [defaults objectForKey:@"AppleLanguages"];
NSLog(@"%@", languages);
2012年12月7日 星期五
how to call shouldautorotatetointerfaceorientation
這個問題是我一個朋友問我的
覺得有可能需要紀錄下來
朋友的問題是
一開始假設機器是橫的
然後我拖動畫面~把開關設成NO~然後轉機器~這時候到了shouldAutorotateToInterfaceOrientation會因為我的布林值而不去旋轉畫面~但是事實上機器已經被設定成直式了
然後我放開後再去檢查機器的方向~這時候我會查到機器是直的~然後做直的layout~但是機器的畫面卻是橫的
所以畫面就整個不對了
最後結論就是
簡單來說就是怎麼去重新觸發shouldAutorotateToInterfaceOrientation
If you are target iOS 5, you can call
[UIViewController attempRotationToDeviceOrientation
which will can shouldAutorotateToInterfaceDeviceOrientation: with the device's current orientation and will rotate the interface if that method returns YES.
參考
http://stackoverflow.com/questions/9051192/iphone-change-orientation-manually
解決囉
覺得有可能需要紀錄下來
朋友的問題是
一開始假設機器是橫的
然後我拖動畫面~把開關設成NO~然後轉機器~這時候到了shouldAutorotateToInterfaceOrientation會因為我的布林值而不去旋轉畫面~但是事實上機器已經被設定成直式了
然後我放開後再去檢查機器的方向~這時候我會查到機器是直的~然後做直的layout~但是機器的畫面卻是橫的
所以畫面就整個不對了
最後結論就是
簡單來說就是怎麼去重新觸發shouldAutorotateToInterfaceOrientation
If you are target iOS 5, you can call
[UIViewController attempRotationToDeviceOrientation
which will can shouldAutorotateToInterfaceDeviceOrientation: with the device's current orientation and will rotate the interface if that method returns YES.
參考
http://stackoverflow.com/questions/9051192/iphone-change-orientation-manually
解決囉
2012年9月25日 星期二
NSArray compare 排序
其實一般NSArray的排序
但是我需要的是針對NSArray多個dictionary,每個dictionary都有個key值為"dddNumber",key值的形態為字串,如何依照NSString比對呢?
是要用intValue排序的话。上面代码是不对的,上面是按照String来排序的。 如果要按照intValue排序,参见如下:
方法
使用
NSArray *sortedArray = [temp_dic_dic sortedArrayUsingSelector:@selector(compare:)];
for(int i =0; i < [sortedArray count]; i++)
{
int x = [[sortedArray objectAtIndex:i] intValue];
NSLog(@"x is %d",x);
}但是我需要的是針對NSArray多個dictionary,每個dictionary都有個key值為"dddNumber",key值的形態為字串,如何依照NSString比對呢?
NSMutableArray *array = [[NSMutableArray alloc] init];
for (int i = 0; i < 10; i ++) {
NSDictionary *aDict = [[NSDictionary alloc] initWithObjectsAndKeys:[NSString stringWithFormat:@"akdj%i", i], @"phaseNumber", nil];
[array addObject:aDict];
[aDict release];
}
// 排序
NSSortDescriptor *sortDescriptor = [[[NSSortDescriptor alloc] initWithKey:@"dddNumber" ascending:YES] autorelease];
NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor];
NSArray *sortedArray = [array sortedArrayUsingDescriptors:sortDescriptors];
是要用intValue排序的话。上面代码是不对的,上面是按照String来排序的。 如果要按照intValue排序,参见如下:
方法
NSComparisonResult compare(NSDictionary *firstDict, NSDictionary *secondDict, void *context) {NSLog(@"IN(%i, %i)", [[firstDict objectForKey:@"ddd"] intValue], [[secondDict objectForKey:@"ddd"] intValue]);
if ([[firstDict objectForKey:@"ddd"] intValue] < [[secondDict objectForKey:@"ddd"] intValue])
return NSOrderedAscending;
else if ([[firstDict objectForKey:@"ddd"] intValue] > [[secondDict objectForKey:@"ddd"] intValue])
return NSOrderedDescending;
else
return NSOrderedSame;
}
[array sortUsingFunction:compare context:NULL];
使用
[array sortUsingFunction:compare context:NULL];
2012年9月5日 星期三
Application does not run in background
在專案的info.plist新增
Application does not run in background
設為YES
Application does not run in background
設為YES
Where is the XCode 4 build directory?
Where is the XCode 4 build directory?
In all previous versions, XCode used to create a build directory inside the project folder and the executables were saved in that location.
However, XCode 4 changed all that.
Infact, I spent quite sometime searching for my executables.
XCode 4 uses the derived data location for storing your builds by default.
Just click on the XCode menu on the top bar, and select Preferences -> Locations tab.
Here under build location, you can see the default setting selected as "place build products in derived data location (recommended)".
And if you check the "Derived Data Location" section of this tab you will see the default location is /Users/..../Library/Developer/XCode/DerivedData.
You will see a small arrow next to this path and clicking on it takes you directly to this location and voila there is your build directory!
However, XCode 4 changed all that.
Infact, I spent quite sometime searching for my executables.
XCode 4 uses the derived data location for storing your builds by default.
Just click on the XCode menu on the top bar, and select Preferences -> Locations tab.
Here under build location, you can see the default setting selected as "place build products in derived data location (recommended)".
And if you check the "Derived Data Location" section of this tab you will see the default location is /Users/..../Library/Developer/XCode/DerivedData.
You will see a small arrow next to this path and clicking on it takes you directly to this location and voila there is your build directory!
訂閱:
文章 (Atom)
