开发者

app crashes when going back to edit screen [closed]

开发者 https://www.devze.com 2023-03-30 00:21 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 10 years ago.

I am trying to build the RSS feeds part of my application but it seems to keep crashing whenever I make a change to the database. What I have is a list of a few rss feed, with an edit button in the naviagtionbar, clicking edit takes you to a page which allows selecting which rss feeds to show on the first page by using switches. The switches just change an integer value in the db

first page

#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)didReceiveMemoryWarni开发者_如何学运维ng {
    // 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

second page

//
//  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

stack trace

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) 


by stack trace i would say you calling -[NSMutable<Array,Dictionary,Set> removeAllObjects] on dealoced object

0

精彩评论

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