UITableViewにbeatportのジャンルのリストを表示するのに一番スマートな方法を模索していていい感じにやる方法がわかったのでメモ。
ベタにコードに書かずにプロパティリストエディタでgenre.plistを作成しリソースに追加する。

テーブルビューに表示する名称の配列とジャンルのデータを定義する
@interface RootViewController : UITableViewController {
NSArray* names;
NSDictionary *dictGenre;
}
@property (retain) NSArray* names;
@property (retain) NSDictionary* dictGenre;
プロパティリストファイルをNSDictionaryクラスに読み込み、キー一覧をソートしてNSArrayオブジェクトへ展開する迄
// Genre.plistの読み込み NSString *pathGenre = [[NSBundle mainBundle] pathForResource:@"Genre" ofType:@"plist"]; // RootViewControllerを取得 RootViewController* rootViewController; rootViewController = (RootViewController*)navigationController.topViewController; rootViewController.title = @"Grenres"; rootViewController.dictGenre = [NSDictionary dictionaryWithContentsOfFile:pathGenre]; // NSDicronayのkeyを配列に取り出してソート NSArray *sortedArray =[[rootViewController.dictGenre allKeys] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)]; rootViewController.names = sortedArray;
UITableViewのセル描写のコールバックでソートしたジャンル名を表示してやる。
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [names count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
cell.text = [names objectAtIndex:indexPath.row];
return cell;
}
ウホッ

tAkatronixおすすめのiPhone開発本
iPhone デベロッパーズ クックブック
posted with amazlet at 10.01.31
Erica Sadun
ソフトバンククリエイティブ
売り上げランキング: 84906
ソフトバンククリエイティブ
売り上げランキング: 84906
詳解 Objective-C 2.0
posted with amazlet at 10.01.31
荻原 剛志
ソフトバンククリエイティブ
売り上げランキング: 4163
ソフトバンククリエイティブ
売り上げランキング: 4163
iPhoneプログラミングUIKit詳解リファレンス
posted with amazlet at 10.01.31
所 友太
リックテレコム
売り上げランキング: 3089
リックテレコム
売り上げランキング: 3089
iPhone Core Audioプログラミング
posted with amazlet at 10.01.31
永野 哲久
ソフトバンククリエイティブ
売り上げランキング: 22615
ソフトバンククリエイティブ
売り上げランキング: 22615






FREEEK iPhone App 2.0 on iTunes App Store!!
Photo Album
One comment
I got jacked on usfreeads by some jerkwad using a mobile line. Jerkwad was shocked when I got her addy info and came calling lol!
Reverse Number Lookup