iPhone開発のテクニック

10102 ワード

1.uiviewcontrollerでnsstring propertyを宣言する方法:
NSString *groupName;
@property (nonatomic, assign) NSString *groupName;
2.Setting the back button title of a UINavigationItem
The following code will set the back button title of the current UINavigationItem:
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:nil action:nil];
[self.navigationItem setBackBarButtonItem:backButton];
[backButton release];

The target: and action: parameters are definitely ignored (replaced by the default back button behavior) and the style also seems to be ignored because the back button retains its pointed left side.
This next block of code looks like it should do the same thing but does not work:
self.navigationItem.backBarButtonItem.title = [NSString stringWithString:@"Back"];
注意:backbarbuttonitemは必ず現在のページに設定してください!!
MAJOR CAVEAT: As pointed out in this thread, "the back button is 'owned' by the previous view on the stack."In other words, the setBackBarButtonItem method should be called on the view that the user is navigating away from, rather than the view above which this button is actually displayed.
3.tableviewcell背景色の調整
UITableViewCell *bgView = [[UITableViewCell alloc] initWithFrame:CGRectZero];
    bgView.backgroundColor=indexPath.row % 2? [UIColor colorWithRed:0.95 green:0.95 blue:0.95 alpha:1]: [UIColor whiteColor];
    bgView.accessoryView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"disclosure.png"]];
    cell.backgroundView=bgView; 
    return cell;

4.ipad背景透明
tableView.backgroundColor = [UIColor clearColor];
iPhoneでは透明ですが、iPadでは無効です.
解決策:ttable.backgroundView.alpha = 0;
5.アイコンリソース
Ever reach a brick wall in designing your app due to a shortage of artwork? I ran into this situation this morning, and figured I’d share what I’ve found for others that might be similarly design handicapped.
iPhone Tab Bar Icons
GlyFX has a few sets available for purchase at
http://www.glyfx.com/shop/listing/iphone/
GLYPHISH has a large set for free at
http://glyphish.com/
Quality Icons Blog has a few free gaming focused icons available here
http://qualityicons.blogspot.com/2009/08/iphone-tab-bar-gaming-icons.html
eddit has a 160+ icon set you can purchase here
http://www.eddit.com/shop/iphone_ui_icon_set/
kombine has a 130+ icon set for sale at
http://www.kombine.net/icon-store/iphone-tab-bar-icons
Just remember your app can get rejected for the incorrect use of icons or breaking the iPhone Human Interface Guidelines. I found the blog post “icon fail” by Under the Bridge extremely helpful in understanding the importance of selecting your icons.
6. How to make your own tab bar icon
http://www.youtube.com/watch?v=YUWMeJq9f-8
http://www.aha-soft.com/faq/ios-toolbar-icons.htm
http://speckyboy.com/2010/04/30/iphone-and-ipad-development-gui-kits-stencils-and-icons/
7.各種アイコンサイズ
http://www.axialis.com/tutorials/make-ipad-icons.html#t2
8. Resizing a UITableViewCell to Hold Variable Amounts of Text
http://www.raddonline.com/blogs/geek-journal/iphone-sdk-resizing-a-uitableviewcell-to-hold-variable-amounts-of-text/
9. RoundedUITableView for iOS
http://www.cocoacontrols.com/platforms/ios/controls/roundeduitableview
10.navigationcontrollerからtoolbarを非表示にするとアニメーションを非表示にするとシャドウが発生します.解決策としてnavigationcontrollerが持参したtoolbarを使用せず、自分でuiviewにtoolbarを追加します.
- (void)viewDidLoad
{
    // Add a toolbar to the view
    CGRect toolbarFrame = CGRectMake(0, 372, 320, 44);
    UIToolbar *myToolbar = [[UIToolbar alloc] initWithFrame:toolbarFrame];

    UIBarButtonItem *compassButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"compass.png"]
                                                                      style:UIBarButtonItemStyleBordered
                                                                     target:self
                                                                     action:@selector(zoomToCurrentLocation)];

    compassButton.width = 30.0f; // make the button a square shape
    [myToolbar setItems:[NSArray arrayWithObject:compassButton] animated:NO];
    [compassButton release];

    [self.view addSubview:myToolbar];
    [super viewDidLoad];
}

11. How to compare if two objects are really the same object?
The == operator tests whether the two expressions are the same pointer to the same object. Cocoa calls this relation “identical” (see, for example, NSArray's indexOfObjectIdenticalTo:).
To test whether two objects are equal, you would send one of them an isEqual: message (or a more specific message, such as isEqualToString:, if it responds to one), passing the other object. This would return YES if you really only have one object (equal to itself, obviously) or if you have two objects that are equal. In the latter case, == will evaluate to NO.
12.IOSがサポートするすべてのフォントfont
http://iosfonts.com/
13. Advanced App Tricks
http://developer.apple.com/library/ios/#documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/AdvancedAppTricks/AdvancedAppTricks.html
14.パスワードの入力画面:
https://github.com/Koolistov/Passcode
http://code.google.com/p/kpasscode/
15.プログラムとiTunes間でファイルを共有する
http://www.alterplay.com/ios-dev-tips/2010/11/file-sharing-from-app-to-itunes-is-too-easy.html
16.
http://stackoverflow.com/questions/7989968/iphone-loading-view-slide-effect
1、一つのviewにsuperViewがあるかどうかを判断する
if ( [scrollView superviews] )
{
     [scrollView removeFromSuperView];
}
else
{
    [self.view addSubView:scrollView];
}
2、tableviewの青色選択を外す
バータブビューのセレクションをNoセレクションに変更すればよい.
3、親viewのコントロールを呼び出す方法
[[self superview ].nextResponder  method];
[[[self superview ] nextResponder]  method];
[self.nextResponder method];
上のものはすべて可能で、状況によって使用して、使う時は判断したほうがいいです.
公式解釈
UIView implements this method by returning the UIViewController object that manages it (if it has one) or its superview (if it doesn’t); UIViewController implements the method by returning its view’s superview; UIWindow returns the application object, and UIApplication returns nil.
4、tab bar controllerのtab barを隠す方法
Iphoneプログラミングでは、Tab bar controllerとNavを混ぜて使うのが好きな人が多く、Tab barの上のボタンをクリックして別のviewに切り替えたとき、インタフェースのTab Barは消えなかった.
viewの一部のインタフェースが遮断された.Tab Barを隠す必要があります.隠しコードは次のとおりです.
self.newView = [[newViewController alloc] init];
newView.hidesBottomBarWhenPushed=YES;
[self.navigationController presentModalViewController:newView animated:YES];
新しいビューを作成するときに参加します
newView.hidesBottomBarWhenPushed=YES;
Tab Barを消すことができる.
5、
UIsearchBar動作処理
/*キャンセルボタン*/
- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar{ 
    [self doSearch:searchBar]; 

 
/*キーボード検索ボタン*/
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{ 
    [searchBar resignFirstResponder]; 
    [self doSearch:searchBar]; 

 
/*検索*/
- (void)doSearch:(UISearchBar *)searchBar{ 
    ... 

UIsearchBar上のボタンのデフォルト文字はCancelですが、他の文字に変更したい場合はコードを呼び出してください
for(id cc in [searchtext subviews]){ 
   if([cc isKindOfClass:[UIButton class]]){ 
       UIButton *btn = (UIButton *)cc; 
[btn settTitle:@"キャンセル"forState:UIcontrolStateNormal]; 
   } 

注意:hファイル種追加
,そして.mファイル種設定SearchBarの依頼は次のとおりです.
self.SearchBar.delegate =self;有効になります.
6、制御Default.pngピクチャの表示時間
直接delegateに
sleep(延長したい秒数);
7、UIsearchBarキーボードのSearchキーを別の名前に変更する:
UITextField *searchField = [[search subviews] lastObject];
[searchField setReturnKeyType:UIReturnKeyDone];
8、UItabBarController下のTabBarItemメニューをクリックした場合、どのように再ロードしますか?
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
//NSLog(@「一度ロード」);
//ロードするたびに実行する内容をここに追加
}