0

我正在尝试使用内部的 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 有关viewDidLoadinitWithNibName但我无法弄清楚它是什么。

我试图交换viewDidLoadwithloadView但这只是产生了一个不同的错误。

提前致谢!

4

1 回答 1

2

您已经使用方便的方法(即没有 allo/init/retain)初始化了 tableData。所以数组会自动释放。

尝试使用

tableData=[[NSArray alloc] initWithObjects:...];
于 2013-04-15T14:34:24.707 回答