Iphone 使用tableView启动新视图时的EXC_错误访问

Iphone 使用tableView启动新视图时的EXC_错误访问,iphone,ios,objective-c,uiviewcontroller,tableview,Iphone,Ios,Objective C,Uiviewcontroller,Tableview,我正在尝试启动一个新的viewController,里面有一个tableView,但我一直收到EXC_BAD_访问错误 h 我在返回[tableData count]时遇到异常行,但我认为问题与如何在viewdiload和initWithNibName中启动viewController有关,但我无法确定它是什么 我曾尝试将viewDidLoad与loadView交换,但这只是产生了一个不同的错误 提前谢谢 您已经使用一种方便的方法(即不使用allo/init/retain)初始化了tableDa

我正在尝试启动一个新的viewController,里面有一个tableView,但我一直收到EXC_BAD_访问错误

h

我在
返回[tableData count]时遇到异常numberOfRowsInSection
方法中的code>行,但我认为问题与如何在
viewdiload
initWithNibName
中启动viewController有关,但我无法确定它是什么

我曾尝试将
viewDidLoad
loadView
交换,但这只是产生了一个不同的错误


提前谢谢

您已经使用一种方便的方法(即不使用allo/init/retain)初始化了tableData。因此阵列将自动释放

试用

tableData=[[NSArray alloc] initWithObjects:...];

你是救命恩人!作品谢谢你这么快的回答。将在时间限制到期时接受。最好使用属性(或切换到ARC)。否则,如果您之前没有释放
tableData
,则在多次调用
viewDidLoad
的情况下(如果您的视图由于内存不足而临时卸载,则在iOS 5及以下版本上会发生泄漏)。
@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
tableData=[[NSArray alloc] initWithObjects:...];