EXC BAD ACCESS POINT错误

时间:2011-09-30 19:59:28

标签: iphone

我正在尝试创建一个列表,一个应用程序收藏夹列表,你保存在一个可变数组中,然后保存为用户默认值,但是当我点击一个单元格或者我点击时,我一直收到错误的访问点错误转到另一个视图然后回到这个视图请帮助这是我的代码

- (void)viewDidLoad {
        [super viewDidLoad];
        listOfItems=[[NSUserDefaults standardUserDefaults] mutableArrayValueForKey:@"favorites"];
    }

//在加载视图后实现viewDidLoad以进行其他设置,通常是从笔尖。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return (interfaceOrientation==UIInterfaceOrientationPortrait);
}


- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc. that aren't in use.
}
-(void)viewWillAppear:(BOOL)animated {
    //Save mutable array and save to table set.
    listOfItems=[[NSUserDefaults standardUserDefaults] mutableArrayValueForKey:@"favorites"];

    [self.tableView reloadData];
}

- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}


// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [listOfItems count];
}


// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
    }

    // Set up the cell...
    NSString *cellValue = [listOfItems objectAtIndex:indexPath.row];
    cell.textLabel.text = cellValue;

    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {


    [self presentModalViewController:deffinitionviewController animated:YES];


}







please help

1 个答案:

答案 0 :(得分:1)

你应该保留listOfItems:

if(listOfItems)
    [listOfItems release];   // use this so it doesn't leak (also remember to release it in dealloc)
listOfItems=[[[NSUserDefaults standardUserDefaults] mutableArrayValueForKey:@"favorites"] retain];