Note that there are some explanatory texts on larger screens.

plurals
  1. PO_tableView reloadData crashes my app
    primarykey
    data
    text
    <p>In the remove method my program seems to be doing fine until it exits and throws an out of bounds exception. It removes the item correctly from the mutable array that my table view (tableView2) is connected to. My tables are connected to the delegate and datasource correctly. The exception is thrown after the reloadData line. I had this method working on a different version that I lost in an OS reinstallation, but I thought this is how I had it working before. Any suggestions would be greatly appreciated!</p> <p>Error:</p> <pre><code>2013-08-29 00:48:58.451 Event Sign-In[770:11303] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array' *** First throw call stack: (0x1c94012 0x10d1e7e 0x1c360b4 0x27a4 0xd08fb 0xd09cf 0xb91bb 0xc9b4b 0x662dd 0x10e56b0 0x2290fc0 0x228533c 0x2285150 0x22030bc 0x2204227 0x22048e2 0x1c5cafe 0x1c5ca3d 0x1c3a7c2 0x1c39f44 0x1c39e1b 0x1bee7e3 0x1bee668 0x15ffc 0x1cdd 0x1c05 0x1) libc++abi.dylib: terminate called throwing an exception (lldb) .h: #import &lt;UIKit/UIKit.h&gt; @interface ViewController : UIViewController &lt;UITableViewDataSource, UITableViewDelegate&gt;{ UITableView *tableView; } @property (weak, nonatomic) IBOutlet UITextField *nameField; @property (nonatomic, retain) NSMutableArray *names; @property (nonatomic, retain) NSMutableArray *existingNames; @property (nonatomic, retain) NSMutableArray *companies; @property (nonatomic, retain) NSMutableArray *namesAndCompanies; - (IBAction)add:(id)sender; - (IBAction)addExisting:(id)sender; - (IBAction)Edit:(id)sender; - (IBAction)Remove:(id)sender; - (IBAction)submit:(id)sender; - (IBAction)removeAll:(id)sender; @property (strong, nonatomic) IBOutlet UITableView *tableView1; @property (weak, nonatomic) IBOutlet UITableView *tableView2; @property (strong, nonatomic) IBOutlet UITableView *companiesTable; @end </code></pre> <p>.m:</p> <pre><code>#import "ViewController.h" #import &lt;MessageUI/MessageUI.h&gt; @interface ViewController () &lt;MFMailComposeViewControllerDelegate&gt; @end @implementation ViewController @synthesize nameField; @synthesize names; @synthesize companies; @synthesize existingNames; @synthesize namesAndCompanies; @synthesize tableView1 = _tableView1; @synthesize tableView2 = _tableView2; @synthesize companiesTable = _companiesTable; int rowNumber1; int rowNumber2; int companyRowNumber; - (void)viewDidLoad { [super viewDidLoad]; self.names = [[NSMutableArray alloc] init]; self.existingNames = [[NSMutableArray alloc] init]; self.namesAndCompanies = [[NSMutableArray alloc] init]; self.companies = [NSArray arrayWithObjects:@"Morgridge", @"WID", @"WARF", @"Other", nil]; // Do any additional setup after loading the view, typically from a nib. } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if (tableView == self.tableView1){ return [existingNames count]; } else if (tableView == self.tableView2){ return [names count]; } else if (tableView == self.companiesTable){ return [companies count]; } return 0; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *simpleTableIdentifier = @"SimpleTableItem"; UITableViewCell *cell; if (tableView == self.tableView1){ cell = [_tableView1 dequeueReusableCellWithIdentifier:simpleTableIdentifier]; } else if (tableView == self.tableView2){ cell = [_tableView2 dequeueReusableCellWithIdentifier:simpleTableIdentifier]; } else if (tableView == self.companiesTable){ cell = [_companiesTable dequeueReusableCellWithIdentifier:simpleTableIdentifier]; } if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier]; } if (tableView == self.tableView1){ cell.textLabel.text = [existingNames objectAtIndex:indexPath.row]; } else if (tableView == self.tableView2){ cell.textLabel.text = [namesAndCompanies objectAtIndex:indexPath.row]; } else if (tableView == self.companiesTable){ cell.textLabel.text = [companies objectAtIndex:indexPath.row]; } return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ if (tableView == self.tableView1){ rowNumber1 = indexPath.row; } else if (tableView == self.tableView2){ rowNumber2 = indexPath.row; } else if (tableView == self.companiesTable){ companyRowNumber = indexPath.row; } } - (IBAction)add:(id)sender { if ([nameField.text isEqualToString:@""]){ return; } BOOL exists = [names containsObject:nameField.text]; if(exists == FALSE){ NSMutableString *nameAndCompany = nameField.text; [nameAndCompany appendString:@", "]; [nameAndCompany appendString:[companies objectAtIndex:companyRowNumber]]; [names addObject:nameField.text]; [namesAndCompanies addObject:nameAndCompany]; [existingNames addObject:nameAndCompany]; } else{ UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"A user with that name already exists." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show]; } [names sortUsingSelector:@selector(compare:)]; [namesAndCompanies sortUsingSelector:@selector(compare:)]; [existingNames sortUsingSelector:@selector(compare:)]; [_companiesTable deselectRowAtIndexPath:[_companiesTable indexPathForSelectedRow] animated:YES]; [self.view endEditing:YES]; [_tableView1 reloadData]; [_tableView2 reloadData]; nameField.text=@""; } - (IBAction)addExisting:(id)sender { if ([existingNames containsObject:[namesAndCompanies objectAtIndex:rowNumber1]]){ return; } [existingNames addObject:[namesAndCompanies objectAtIndex:rowNumber1]]; [existingNames sortUsingSelector:@selector(compare:)]; [_tableView1 deselectRowAtIndexPath:[_tableView1 indexPathForSelectedRow] animated:YES]; [_tableView2 reloadData]; } - (IBAction)Edit:(id)sender { int toDelete = rowNumber1; nameField.text = [names objectAtIndex:rowNumber1]; if ([namesAndCompanies containsObject:[existingNames objectAtIndex:rowNumber1]]){ [namesAndCompanies removeObjectIdenticalTo:[existingNames objectAtIndex:rowNumber1]]; } [existingNames removeObjectAtIndex:toDelete]; [names removeObjectAtIndex:toDelete]; [_tableView1 deselectRowAtIndexPath:[_tableView1 indexPathForSelectedRow] animated:YES]; [_tableView1 reloadData]; [_tableView2 reloadData]; } - (IBAction)Remove:(id)sender { [namesAndCompanies removeObjectAtIndex:rowNumber2]; [_tableView2 reloadData]; } - (IBAction)removeAll:(id)sender { } @end </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload