以下のページを参考にしたのですが、チェックマークが付きません。
http://mako-wis.hatenablog.com/entry/2014/03/07/110322
セルが選択された際に実行されるメソッド内で
cell.accessoryType = UITableViewCellAccessoryCheckmark;
を実行しているので、問題なくチェックマークが付くと考えていますが、付きません。
間違っているところがあるためチェックマークが付かないと思うのですが、
そこがわからずでして、、、
お手数ですがご教示をお願いします。
◆ViewController.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController<UITableViewDelegate, UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@end
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.tableView.delegate = self;
self.tableView.dataSource = self;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return [NSString stringWithFormat:@"section%ld", (long)section];
}
// セルの数:10
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 10;
}
// indexPathで指定されたcellに値をセット
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
}
// セルの内容をindexPath.rowとする
cell.textLabel.text = [NSString stringWithFormat:@"%d", indexPath.row];
return cell;
}
// セルが選択された時に呼び出される
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// 選択されたセルを取得
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
// 選択されたセルの内容をログに出力
NSLog(@"cell.textLabel.text=%@", cell.textLabel.text);
// セルのアクセサリにチェックマークを指定
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
@end