开发者

EXC BAD ACCESS POINT error

HI I'm trying to create a list an app for favorites list that you save in a mutable array which then gets saved as a user defaults but I keep getting bad access point errors either when i click on a cell or if I go to another view and then go back to this view please help this is my code

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

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.

- (BOOL)shouldAutorotateToInterfaceOrientation:(UI开发者_如何学CInterfaceOrientation)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


You should retain 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];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜