Steve
Steve

Reputation: 205

Single Tab in a Tabbed-iOS Application keeps crashing

I am using the BWRSS RSS Feed wrapper in my tabbed iPhone/iPad application. I am using the latest Xcode Version and I also have had two versions submitted and accepted. The First of which worked perfectly, but the Second Works on the iPhone, but not on the iPad(Though it was accepted). The problem seems to stem from the tab that has the RSS feeds. All of the tabs will work fine in the app, except for the one RSS Tab. Now that single tab won't even work with the iPhone version when I test it in the Ad Hoc.(It will work with the normal Building & Running.) I have tried to do the Snapshots thing, but now the ones that had been working aren't anymore. I have tried to change many things to fix it, but nothing seems to work.

I have tried for the last month to fix the issue, but I can't figure it out. I have used the iPhone Configuration Utility to find the source of the crash and here it is:

MBBC[5135] <Error>: *** Terminating app due to uncaught exception         
'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: 
object cannot be nil'
*** First throw call stack:
(0x32a7a2a3 0x3a7a297f 0x329c48d9 0xa1715
0xa46f7 0xa3e59 0x348e9311 0x348f579b 0x348f54c1 
0x348c64e9 0x34885803 0x3462fd8b 0x3462f929 0x3463085d 
0x34630243 0x34630051 0x3488b8eb 0x32a4f6cd 0x32a4d9c1 
0x32a4dd17 0x329c0ebd 0x329c0d49 0x365992eb 0x348d6301 0x9f87f 0x3abd9b20)

I Have to use the iPhone Configuration Utility because the crash only occurs in Ad Hoc Testing.

Here is the code for the View controller that should appear when the tab is opened.

#import "BWRSSFeedsTableViewController.h"
#import "BWRSSItemsTableViewController.h"
#import "Reachability.h"

@interface BWRSSFeedsTableViewController () {
    BOOL iPadIdiom;
    NSDictionary * _newFeed;
    RSSDB * _rssDB;
    NSArray * _feedIDs;
    BOOL bannerIsVisible;
}
@end

@implementation BWRSSFeedsTableViewController

- (void) viewWillAppear:(BOOL)animated {

    [super viewWillAppear:animated];

    if (UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad) iPadIdiom = YES;
    [self loadFeedIDs];
    [self.tableView reloadData];
}

- (void) viewDidAppear:(BOOL)animated {
    if (_newFeed)  [self loadNewFeed];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.title = @"RSS Feeds";
    // Do any additional setup after loading the view, typically from a nib.

}
- (void)didReceiveMemoryWarning
{
   [super didReceiveMemoryWarning];
   // Dispose of any resources that can be recreated.
}

#pragma mark - Segue delegate

- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if ([segue.identifier isEqualToString:@"SegueToItemTableView"]) {
        BWRSSItemsTableViewController * itemsTableViewController = [segue destinationViewController];
        NSIndexPath * path = [self.tableView indexPathForSelectedRow];
        NSNumber * feedID = _feedIDs[path.row];



        itemsTableViewController.currentFeedID = feedID;
        itemsTableViewController.rssDB = _rssDB;
    } 
    else if([segue.identifier isEqualToString:@"SegueToAddView"]) {

        BWRSSAddViewController *rssAddViewController = [segue destinationViewController];
        rssAddViewController.delegate = self;
     }
}

#pragma mark - Table View

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

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    [self loadFeedIDs];
    return _feedIDs.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"FeedsCell" forIndexPath:indexPath];
    [self loadFeedIDsIfEmpty];
    NSDictionary * feedRow = [_rssDB getFeedRow:_feedIDs[indexPath.row]];
    cell.textLabel.text = feedRow[@"title"];
    cell.detailTextLabel.text = feedRow[@"desc"];
    return cell;
}

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{

    // Return NO if you do not want the specified item to be editable.
    return NO;
}




#pragma mark - Database methods

- (void) loadNewFeed {
    // NSLog(@"%s", __FUNCTION__);
    if (!_newFeed) return;

    NSDictionary * newFeed = _newFeed;
    _newFeed = nil;

    NSNumber * rc = [_rssDB addFeedRow:newFeed];
    NSIndexPath * idx = [self indexPathForDBRec:newFeed];
    if (rc == nil) {    // inserted row in DB
        [self.tableView insertRowsAtIndexPaths:@[idx] withRowAnimation:UITableViewRowAnimationLeft];
    }
    [self.tableView scrollToRowAtIndexPath:idx atScrollPosition:UITableViewScrollPositionNone animated:YES];
    if (rc != nil) {    // updated existing row in DB
        [self.tableView reloadRowsAtIndexPaths:@[idx] withRowAnimation:UITableViewRowAnimationLeft];
    }
}

- (NSIndexPath *) indexPathForDBRec:(NSDictionary *) dbRec {
    NSNumber * rowID = [_rssDB valueFromQuery:@"SELECT id FROM feed WHERE url = ?", dbRec[@"url"]];
    if (rowID) {
        NSArray * tempFeedIDs = [_rssDB getFeedIDs];
        return [NSIndexPath indexPathForRow:[tempFeedIDs indexOfObject:rowID] inSection:0];
    } else {
        return nil;
    }
}

- (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__);
     // use self.rssDB? or rssDB?
     if (!_rssDB) _rssDB = [[RSSDB alloc] initWithRSSDBFilename:@"bwrss.db"];
    return _rssDB;
}


@end

Please tell me if their is anything else I should add that you all might need to help me with this really annoying issue. Thanks!!!

New iPhone Config Output:

 MBBC[5750] <Error>: *** Terminating app due to uncaught exception        
'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'
*** First throw call stack:
(0x32a7a2a3 0x3a7a297f 0x329c48d9 0xe56c5 0xe86fb 0xe7e5b 0x348e9311 0x348f579b     
    0x348f54c1 0x348c64e9 0x34885803 
    0x3462fd8b 0x3462f929 0x3463085d 0x34630243 
    0x34630051 0x3488b8eb 0x32a4f6cd 0x32a4d9c1 0x32a4dd17
    0x329c0ebd 0x329c0d49 0x365992eb 0x348d6301 0xe382f 0x3abd9b20)
    Apr 21 12:36:40 iPhone ReportCrash[5752] <Notice>: Formulating crash report for process MBBC[5750]
    Apr 21 12:36:40 iPhone com.apple.launchd[1] (UIKitApplication:MBBC.App[0x7a64][5750])          
    <Warning>: (UIKitApplication:MBBC.App[0x7a64]) Job appears to have crashed: Abort trap: 6
    Apr 21 12:36:40 iPhone backboardd[26] <Warning>: Application 'UIKitApplication:MBBC.App[0x7a64]' 
    exited abnormally with signal 6: Abort trap: 6
    Apr 21 12:36:40 iPhone ReportCrash[5752] <Error>: libMobileGestalt          
    copySystemVersionDictionaryValue: Could not lookup ReleaseType from system version dictionary

I see that it is crashing on 6 something, but I don't know exactly what that means

Link to Image:I wouldn't let me upload it to this website, though I have uploaded images before: https://docs.google.com/file/d/0BxE5vJUTZp7eVWxvRW0wd2pEN2c/edit?usp=sharing

UPDATE:I have also tried restarting from scratch and just importing the files and checking each file, one-by-one as I import them

UPDATE 2: I added a link to part of my storyboard. It wouldn't let me upload it!!!

UPDATE 3: I updated with what it is giving me now when I added the exception Breakpoint

Upvotes: 0

Views: 350

Answers (1)

David Hoerl
David Hoerl

Reputation: 41642

Add an exception breakpoint to your project, and look at the call chain - you will certainly find the problem. The most likely scenario is that you create some object but don't have a strong reference to it all the time, so the system is releasing it in some cases before you want it to. A common failure path is niling an ivar in a delegate method instead of posting a nil in a block.

Upvotes: 1

Related Questions