我正在尝试使用内部的 tableView 启动一个新的 viewController,但我不断收到 EXC_BAD_ACCESS 错误。
。H
#import <UIKit/UIKit.h>
@interface GeneralInfoViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
@end
.m
@interface GeneralInfoViewController ()
@end
@implementation GeneralInfoViewController
{
NSArray *tableData;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
self.title = @"Allmänna uppgifter";
[super viewDidLoad];
// Initialize table data
tableData = [NSArray arrayWithObjects:@"Egg Benedict", @"Mushroom Risotto", nil];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [tableData count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"SimpleTableItem";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
cell.textLabel.text = [tableData objectAtIndex:indexPath.row];
return cell;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)dealloc {
[super dealloc];
}
- (void)viewDidUnload {
[super viewDidUnload];
}
@end
我在方法中遇到异常,return [tableData count];
但numberOfRowsInSection
我认为问题与我如何在中启动 viewController 有关viewDidLoad
,initWithNibName
但我无法弄清楚它是什么。
我试图交换viewDidLoad
withloadView
但这只是产生了一个不同的错误。
提前致谢!