Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8275967
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:14:23+00:00 2026-06-08T08:14:23+00:00

My app was running fine, I’ve not modified it to have a dedicated data

  • 0

My app was running fine, I’ve not modified it to have a dedicated data controller class rather than the data being handled in the main UI class as it was during initial testing. However since the change it keeps crashing when adding a new item to the tableview.

The line of code and error it’s crashing on are;

[self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];

2012-07-22 07:17:44.772 speecher[1897:707] * Terminating app due to
uncaught exception ‘NSInternalInconsistencyException’, reason:
‘attempt to insert row 0 into section 0, but there are only 0 rows in
section 0 after the update’

The full code for that class, (the main MasterViewController class) is as follows.

//
//  SpeecherMasterViewController.m
//  speecher
//
//

#import "SpeecherMasterViewController.h"
#import "SpeecherDataController.h"
#import "SpeecherDetailViewController.h"

@interface SpeecherMasterViewController () {

    NSString *newTitle;
    NSMutableArray *_speeches;
    NSMutableArray *_content;
    SpeecherDataController *object;

}
@end

@implementation SpeecherMasterViewController

@synthesize detailViewController = _detailViewController;

- (void)awakeFromNib
{
    self.clearsSelectionOnViewWillAppear = NO;
    self.contentSizeForViewInPopover = CGSizeMake(320.0, 600.0);
    [super awakeFromNib];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.navigationItem.leftBarButtonItem = self.editButtonItem;

    UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(insertNewObject:)];
    self.navigationItem.rightBarButtonItem = addButton;
    self.detailViewController = (SpeecherDetailViewController *)[[self.splitViewController.viewControllers lastObject] topViewController];
    object = [[SpeecherDataController alloc] init];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

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


#pragma mark - Table View

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

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [object returnNoObjects];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
    cell.textLabel.text = [object returnTitle:indexPath.row];
    return cell;
}

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return NO if you do not want the specified item to be editable.
    return YES;
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        [_speeches removeObjectAtIndex:indexPath.row];
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.
    }
}

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{


    NSString *titleobj = [object returnTitle:indexPath.row];
    NSString *contentobj = [object returnContent:indexPath.row];
    self.detailViewController.detailItem = titleobj;
    self.detailViewController.detaitContent = contentobj;
}



- (void)insertNewObject:(id)sender
{
    //Make sure clear before we start, also make sure initalized (double redundancy with clear statement at end)
    newTitle = @"";

    //New Title pop up UIAlert View
    UIAlertView * alert = [[UIAlertView alloc] 
                           initWithTitle:@"New Speech" 
                           message:@"Please enter a name for speech" 
                           delegate:self 
                           cancelButtonTitle:@"Create" 
                           otherButtonTitles:nil];

    alert.alertViewStyle = UIAlertViewStylePlainTextInput;

    UITextField * alertTextField = [alert textFieldAtIndex:0];

    alertTextField.keyboardType = UIKeyboardTypeDefault;

    alertTextField.placeholder = @"Enter a new title";
    [alert show];


}



- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{ 
    newTitle = [[alertView textFieldAtIndex:0] text];

    [object addNewContent:newTitle :@"IT REALLY WORKS!" :@"Nothing"];

        //create new speech title, add to array and add to tableview
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
    [self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];

    //Clear newTitle for use next time
    newTitle = @"";

}

@end

EDIT:

Amended to add [object addNewContent] method & class as per comments,

//
//  SpeecherDataController.m
//  speecher
//
//

#import "SpeecherDataController.h"

@interface SpeecherDataController ()
{
    NSMutableArray *titles;
    NSMutableArray *content;
    NSMutableArray *timer;
}
@end

@implementation SpeecherDataController

-(void) addNewContent:(NSString*)sTitle : (NSString*)sContent :(NSString*)sTimer
{
    [titles insertObject:sTitle atIndex:0];
    [content insertObject:sContent atIndex:0];
    [timer insertObject:sTimer atIndex:0];
}


//Methods to return data
-(NSString*) returnTitle:(NSUInteger)row
{
    return [titles objectAtIndex:row];
}

-(NSString*) returnContent:(NSUInteger)row
{
    return [content objectAtIndex:row];
}

-(NSString*) returnTimer:(NSUInteger)row
{
    return [timer objectAtIndex:row];
}

-(NSInteger) returnNoObjects
{
    return titles.count;
}



@end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T08:14:24+00:00Added an answer on June 8, 2026 at 8:14 am

    The problem is the NSMutableArrays hadn’t been alloc and init. Had to add a check to see if they had a init and alloc if not. New check looks like this,

    -(void) addNewContent:(NSString*)sTitle : (NSString*)sContent :(NSString*)sTimer
    {
    
        if(!titles)
        {
            titles = [[NSMutableArray alloc] init];
        }
        if(!content)
        {
            content = [[NSMutableArray alloc] init];
        }
        if(!timer)
        {
            timer = [[NSMutableArray alloc] init];
        }
    
        [titles insertObject:sTitle atIndex:0];
        [content insertObject:sContent atIndex:0];
        [timer insertObject:sTimer atIndex:0];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Silex + Twig app running just fine on Heroku when not
I have a split view app running fine on the iPad. It is using
I have a completed app running in a QA environment. Everything works fine under
I have my in app purchase up and running fine. This is what I
I have a python app running fine on Windows, Linux and Mac which I
I have a python script running fine on my localhost. Its not an enterprise
I have an app written in ruby on rails which is running fine on
I have an app running fine on Heroku and I am attempting to connect
I'm not sure what has happened. My app was running fine, and now every
I have an app that is running fine in the iPhone simulator by way

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.