セルをクリックするとクラッシュします(iOSシミュレーターでアプリが終了します)。エラーコードは
"EXC_BAD_ACCESS(コード= 1、アドレス= 0x310cc493)
コードは次のとおりです。
// .h
#import <UIKit/UIKit.h>
@interface ChecklistsViewController : UITableViewController
@end
// .m
#import "ChecklistsViewController.h"
@interface ChecklistsViewController ()
@end
@implementation ChecklistsViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 100;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ChecklistItem"];
UILabel *label = (UILabel *)[cell viewWithTag:1000];
if (indexPath.row % 5 == 0) {
label.text = @"Walk the dog";
} else if (indexPath.row % 5 == 1) {
label.text = @"Brush my teeth";
} else if (indexPath.row % 5 == 2) {
label.text = @"Learn iOS development";
} else if (indexPath.row % 5 == 3) {
label.text = @"Soccer practice";
} else if (indexPath.row % 5 == 4)
label.text = @"Eat ice cream";
return cell;
}
- tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
} // Control reaches end of non-function
@end