应用程序在返回编辑屏幕时崩溃

时间:2011-08-22 12:45:11

标签: iphone objective-c uinavigationbar edit

我正在尝试构建应用程序的RSS提要部分,但每当我对数据库进行更改时,它似乎都会崩溃。 我所拥有的是一些rss feed的列表,在naviagtionbar中有一个编辑按钮,单击编辑会转到一个页面,该页面允许选择使用开关在第一页上显示哪些RSS源。 这些开关只是更改db

中的整数值

第一页

#import "NewsViewController.h"
#import "NewsAddViewController.h"

@implementation NewsViewController

@synthesize feedIDs, rssDB;

#pragma mark -
#pragma mark View lifecycle

- (void)viewDidLoad {
    [super viewDidLoad];

    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(editFeeds:)];    
}

- (void) editFeeds: (id) sender{
NSLog(@"Editting Feeds");

    NewsAddViewController *newsAddViewController = [[NewsAddViewController alloc]initWithStyle:UITableViewStylePlain];
    newsAddViewController.rssDB = rssDB;
    [self.navigationController pushViewController:newsAddViewController animated:YES];
    newsAddViewController.title=@"Subscriptions";
    [newsAddViewController release];



}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self loadFeedIDs];
    [self.tableView reloadData];
}

#pragma mark -
#pragma mark Table view data source

// Customize the number of sections in the table view.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}


// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    [self loadFeedIDs];
    return [feedIDs 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] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
    }

     // Configure the cell.

    NSDictionary * feedRow = [rssDB getFeedRow:[feedIDs objectAtIndex:indexPath.row]];
    [cell.textLabel setText:[feedRow objectForKey:@"title"]];
    [cell.detailTextLabel setText:[feedRow objectForKey:@"desc"]];
    return cell;
}

#pragma mark -
#pragma mark Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [self loadFeedIDsIfEmpty];

    // clean up aged feed items from the database
    [rssDB deleteOldItems:[feedIDs objectAtIndex:indexPath.row]];

    // create the item view controller
    NewsItemViewController *itemViewController = [[NewsItemViewController alloc] initWithStyle:UITableViewStylePlain];
    itemViewController.rssDB = rssDB;
    itemViewController.feedID = [feedIDs objectAtIndex:indexPath.row];
    [self.navigationController pushViewController:itemViewController animated:YES];
    [itemViewController release];
}

/*
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath {
    [self loadFeedIDsIfEmpty];

    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // must update the database before updating the tableView
        // so that the tableView never has a row that's missing from the database
        [rssDB deleteFeedRow:[feedIDs objectAtIndex:indexPath.row]];
        [self loadFeedIDs];
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];        
    }   
}
*/

#pragma mark -
#pragma mark Memory management

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

    // Relinquish ownership any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
    // Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.
    // For example: self.myOutlet = nil;
}


- (void)dealloc {
    // NSLog(@"%s", __FUNCTION__);
    [super dealloc];
    if (feedIDs) [feedIDs release];
    if (rssDB) [rssDB release];
}

#pragma mark -
#pragma mark Database methods

- (NSArray *) loadFeedIDs {
    // NSLog(@"%s", __FUNCTION__);
    if (!rssDB) [self loadFeedDB];
    feedIDs = [rssDB getFeedIDs];
    return feedIDs;
}

- (NSArray *) loadFeedIDsIfEmpty {
    // NSLog(@"%s", __FUNCTION__);
    if (!rssDB) [self loadFeedDB];
    if (!feedIDs || ![feedIDs count]) feedIDs = [rssDB getFeedIDs];
    return feedIDs;
}

- (RSSDB *) loadFeedDB {
    // NSLog(@"%s", __FUNCTION__);
    if (!rssDB) self.rssDB = [[RSSDB alloc] initWithRSSDBFilename:@"bwrss.db"];
    return rssDB;
}

@end

第二页

//
//  NewsAddViewController.m
//  myUCL
//
//  Created by Lion User on 21/08/2011.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "NewsAddViewController.h"

@implementation NewsAddViewController

@synthesize feedIDs, rssDB;

#pragma mark - View lifecycle

-(void)viewDidLoad {
    [super viewDidLoad];
    [self loadFeedIDs];
    [self.tableView reloadData];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

}


#pragma mark -
#pragma mark Table view data source

// Customize the number of sections in the table view.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}


// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    [self loadFeedIDs];
    return [feedIDs 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:@"SwitchCell"] autorelease];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        UISwitch *switchView = [[UISwitch alloc] initWithFrame:CGRectZero];
        cell.accessoryView = switchView;
        NSDictionary * feedRow = [rssDB getFeedRow:[feedIDs objectAtIndex:indexPath.row]];
        BOOL status = [[feedRow objectForKey:@"show"]boolValue];
        NSLog(@"%i",status);
        [switchView setOn:status animated:NO];
        [switchView addTarget:self action:@selector(switchChanged:) forControlEvents:UIControlEventValueChanged];
        [switchView release];     
        [cell.textLabel setText:[feedRow objectForKey:@"title"]];       
    }
    return cell;
}

- (void) switchChanged:(UISwitch *)sender {
    UISwitch* switchControl = sender;
    //NSLog( @"The switch is %@", switchControl.on ? @"ON" : @"OFF" );
    if (switchControl.on) {
        NSLog(@"switch is on");
       [rssDB updateStatus:[NSNumber numberWithInt:1] :[NSNumber numberWithInt:1]];
        NSLog(@"feed status %@",[rssDB feedStatus:[NSNumber numberWithInt:1]]);

    } else if (!switchControl.on) {
        NSLog(@"switch is off");
        [rssDB updateStatus:[NSNumber numberWithInt:0] :[NSNumber numberWithInt:1]];
        NSLog(@"feed status %@",[rssDB feedStatus:[NSNumber numberWithInt:1]]);
    }
}


#pragma mark -
#pragma mark Memory management

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

    // Relinquish ownership any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
    // Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.
    // For example: self.myOutlet = nil;
}


- (void)dealloc {
    // NSLog(@"%s", __FUNCTION__);
    [super dealloc];
    if (feedIDs) [feedIDs release];
    if (rssDB) [rssDB release];
}
#pragma mark -
#pragma mark Database methods

- (NSArray *) loadFeedIDs {
    // NSLog(@"%s", __FUNCTION__);
    if (!rssDB) [self loadFeedDB];
    feedIDs = [rssDB getAllFeedIDs];
    return feedIDs;
}

- (NSArray *) loadFeedIDsIfEmpty {
    // NSLog(@"%s", __FUNCTION__);
    if (!rssDB) [self loadFeedDB];
    if (!feedIDs || ![feedIDs count]) feedIDs = [rssDB getAllFeedIDs];
    return feedIDs;
}

- (RSSDB *) loadFeedDB {
    // NSLog(@"%s", __FUNCTION__);
    if (!rssDB) self.rssDB = [[RSSDB alloc] initWithRSSDBFilename:@"bwrss.db"];
    return rssDB;
}
@end

堆栈跟踪

2011-08-22 14:03:57.392 myUCL[4890:b303] -[UIGestureRecognizerTarget removeAllObjects]: unrecognized selector sent to instance 0x4cd8cf0
2011-08-22 14:03:57.395 myUCL[4890:b303] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIGestureRecognizerTarget removeAllObjects]: unrecognized selector sent to instance 0x4cd8cf0'
*** Call stack at first throw:
(
    0   CoreFoundation                      0x00e795a9 __exceptionPreprocess + 185
    1   libobjc.A.dylib                     0x00fcd313 objc_exception_throw + 44
    2   CoreFoundation                      0x00e7b0bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
    3   CoreFoundation                      0x00dea966 ___forwarding___ + 966
    4   CoreFoundation                      0x00dea522 _CF_forwarding_prep_0 + 50
    5   myUCL                               0x0000749f -[RSSDB getAllFeedIDs] + 79
    6   myUCL                               0x0000db12 -[NewsAddViewController loadFeedIDs] + 130
    7   myUCL                               0x0000d1b3 -[NewsAddViewController viewDidLoad] + 99
    8   UIKit                               0x0017b089 -[UIViewController view] + 179
    9   UIKit                               0x00179482 -[UIViewController contentScrollView] + 42
    10  UIKit                               0x00189f25 -[UINavigationController _computeAndApplyScrollContentInsetDeltaForViewController:] + 48
    11  UIKit                               0x00188555 -[UINavigationController _layoutViewController:] + 43
    12  UIKit                               0x001897aa -[UINavigationController _startTransition:fromViewController:toViewController:] + 326
    13  UIKit                               0x0018432a -[UINavigationController _startDeferredTransitionIfNeeded] + 266
    14  UIKit                               0x0018b562 -[UINavigationController pushViewController:transition:forceImmediate:] + 932
    15  UIKit                               0x001841c4 -[UINavigationController pushViewController:animated:] + 62
    16  myUCL                               0x0000321f -[NewsViewController editFeeds:] + 255
    17  UIKit                               0x000cb4fd -[UIApplication sendAction:to:from:forEvent:] + 119
    18  UIKit                               0x002ddcc3 -[UIBarButtonItem(UIInternal) _sendAction:withEvent:] + 156
    19  UIKit                               0x000cb4fd -[UIApplication sendAction:to:from:forEvent:] + 119
    20  UIKit                               0x0015b799 -[UIControl sendAction:to:forEvent:] + 67
    21  UIKit                               0x0015dc2b -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
    22  UIKit                               0x0015c7d8 -[UIControl touchesEnded:withEvent:] + 458
    23  UIKit                               0x000efded -[UIWindow _sendTouchesForEvent:] + 567
    24  UIKit                               0x000d0c37 -[UIApplication sendEvent:] + 447
    25  UIKit                               0x000d5f2e _UIApplicationHandleEvent + 7576
    26  GraphicsServices                    0x0110f992 PurpleEventCallback + 1550
    27  CoreFoundation                      0x00e5a944 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
    28  CoreFoundation                      0x00dbacf7 __CFRunLoopDoSource1 + 215
    29  CoreFoundation                      0x00db7f83 __CFRunLoopRun + 979
    30  CoreFoundation                      0x00db7840 CFRunLoopRunSpecific + 208
    31  CoreFoundation                      0x00db7761 CFRunLoopRunInMode + 97
    32  GraphicsServices                    0x0110e1c4 GSEventRunModal + 217
    33  GraphicsServices                    0x0110e289 GSEventRun + 115
    34  UIKit                               0x000d9c93 UIApplicationMain + 1160
    35  myUCL                               0x00001f69 main + 121
    36  myUCL                               0x00001ee5 start + 53
)
terminate called throwing an exceptionCurrent language:  auto; currently objective-c
(gdb) 

1 个答案:

答案 0 :(得分:2)

通过堆栈跟踪

我会说你调用 - [NSMutable< Array,Dictionary,Set>对于dealoced对象

的removeAllObjects]