• 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30

また忘れたのでメモ。
NSIndexPath UIKit Additions というタイトルでiOS 4.3 Libraryに登録されています。

+ (NSIndexPath *)indexPathForRow:(NSUInteger)row inSection:(NSUInteger)section

コードにこんな感じで:

   1      NSIndexPath* indexPath = [NSIndexPath indexPathForRow:0 inSection:0];  

posted by Png satoko on Thu 8 Sep 2011 at 17:07

どこが違うのか気になったのでメモ。 Window-based ApplicationをView-based Applicationと同じところまで持っていく作業を書き出してみます。

※ Xcode 4.1で動作確認しています。

Window-based Applicationを作成

RootViewControllerを作成

File - New - New FileでUIViewControllerテンプレートを選び、RootViewController(.h, .m, .xib)を作成する

Interface Builderで作業

MainWindow.xibを開く
View - Utilities - Show Object Library を開いて、

  1. View ControllerをDrag & Drop

View - Utilities - Show Identity Inspector を開いて、

  1. 先にDropしたView Controllerを選択
  2. Custom ClassのClassをRootViewControllerに
  3. (LabelをRoot View Controllerに)

View - Utilities - Show Attributes Inspector を開いて、

  1. View ControllerのNIB NameをRootViewControllerに

View - Assistant Editor - Show Assistant Editor を開いて、

  1. AppDelegateクラス(h)を開く
  2. IB上でoptionキーを押しながらRoot View Controllerを選択、(hファイル上まで)DragしてInsert Outlet Connectionを追加(Name:viewController)

下記のようにコード生成されます:

   1  @interface RootViewControllerProtoAppDelegate : NSObject <UIApplicationDelegate> {
   2      RootViewController *_viewController;
   3  }
   4  
   5  
   6  @property (nonatomic, retain) IBOutlet UIWindow *window;
   7  @property (nonatomic, retain) IBOutlet RootViewController *viewController;

エディタでの作業

AppDelegateクラスのhで、@classを追加:

   1  @class RootViewController;

AppDelegateクラスのmで、#import、さらにself.viewControllerをself.window.rootViewController

   1  #import "RootViewController.h"
   2  
   3  - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
   4  {
   5      // Override point for customization after application launch.
   6      self.window.rootViewController = self.viewController;
   7      [self.window makeKeyAndVisible];
   8      return YES;
   9  }

厳密に言うと、View-based ApplicationではviewControllerの宣言のされ方が若干違います。そこは各自確認下さいませ。。
作業をしてみてIB経由でクラスにViewController変数を追加するのはやったことなかったので、とても勉強になりました :)

posted by Png satoko on Tue 6 Sep 2011 at 15:32
Contents
UITableView用のNSIndexPathの作り方
Xcodeのテンプレート、View-based ApplicationとWindow-based Applicationの違い
Comments
KingofSmack: Here also good reads for this mobile applicatio... '14-5
satoko: stackoverflowでも同じエラーを挙げている人がいたので、1.3でアップロードしたよっ... '10-12
ujihisa: :%s/blog/glob/g '10-7
satoko: しゅが〜様 返事が遅くなって申し訳ありません。また、投稿百景ご購入ありがとうございます。 ... '09-10
しゅが~: こんにちは。投稿百景を発売日翌日から利用しています。本当にいいAppを作っていただきました。罫... '09-10
Services from s21g
twpro(ツイプロ)
Twitterプロフィールを快適検索
地価2009
土地の値段を調べてみよう
MyRestaurant
自分だけのレストラン手帳
Formula
ブログに数式を埋め込める数式コミュニティ