【解決】Xcode 4.6でiPhoneの着信音画面のような排他リストが作れない
開発環境
Mac OS X 10.8.4
Xcode Version 4.6.2 (4H1003)
iOS シミュレータ 6.0 (369.2)
iOS Table View プログラミングガイド
https://developer.apple.com/jp/devcenter/ios/library/documentation/TableView_iPhone.pdf
のP83「リスト 6-3 選択リストの管理—排他リスト」が正解なのだろうけど、うまくいかない。
「Use of undeclared identifier 'taskCategories'」といわれてXcodeさんに怒られてしまう。
追記 2013.6.29
「【TableView】項目が一つしか選択できないCheckBoxを実装しよう。」
http://blogs.yahoo.co.jp/kilhyungdoo/2126736.html
これで出来た!!やった!!ありがとうございます。
上記の記事の内容をアレンジして、セクションの数と行数を固定値にしないでもいいように、少し手を加えています。
//セルが選択された際に呼び出される
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//選択した後にハイライトを解除
[tableView deselectRowAtIndexPath:indexPath animated:YES];
//返り値=セクションのMax値
// NSLog(@"%d",[tableView numberOfRowsInSection:0]);
for (NSInteger index=0; index<[tableView numberOfRowsInSection:0]; index++) {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:index inSection:indexPath.section]];
cell.accessoryType = UITableViewCellAccessoryNone;
if (indexPath.row == index) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
}
}