酢ろぐ!

カレーが嫌いなスマートフォンアプリプログラマのブログ。

UITableViewを使ってみた

自作アプリをApp Storeで世界に向けて販売できる!! iPhone SDKプログラミング大全 (MacPeople Books)

自作アプリをApp Storeで世界に向けて販売できる!! iPhone SDKプログラミング大全 (MacPeople Books)

自作アプリをApp Storeで世界に向けて販売できる!! iPhone SDKプログラミング大全 (MacPeople Books)」を読みながら、UITableViewを使ったアプリの作り方を勉強しています。UITableViewを使ったチュートリアルのコードで、Amazonのレビューでも指摘されていた「ビルド出来ない」現象がうちでも起こりました。

判る範囲で適当に弄ったら、テキストが書かれたUITableViewCellが無事表示されるようになりました。

**TableAppDelegate.h

|objc| @interface TableAppDelegate : NSObject <UIApplicationDelegate, UITableViewDataSource> { NSArray names; UIWindow window; } ||<

**TableAppDelegate.m

|objc| @implementation TableAppDelegate

@synthesize window;

  • (BOOL)application:(UIApplication )application didFinishLaunchingWithOptions:(NSDictionary )launchOptions {

    // Override point for customization after application launch

    // namesを初期化 names = [[NSArray arrayWithObjects:@"iPhone", @"iPod touch", @"iPod nano", nil] retain];

    [window makeKeyAndVisible];

    return YES; }

  • (void)dealloc { [window release]; [super dealloc]; }

  • (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { // namesの数を返す return [names count]; }

  • (UITableViewCell)tableView:(UITableView)tableView cellForRowAtIndexPath:(NSIndexPath)indexPath { // セルを作る UITableViewCell cell; cell = [tableView dequeueReusableCellWithIdentifier: @"UITableViewCell"]; if (!cell) { cell = [[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier: @"UITableViewCell"]; [cell autorelease]; }

    // セルにテキストを設定する cell.setText = [names objectAtIndex:indexPath.row];

    return cell; }

@end ||<