I tried to run my app and I got signal SIGABRT in the Main.m file and this log message. Help?
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '- [UITableViewController loadView] loaded the "5wY-6u-SFr-view-Zew-TR-1Cy" nib but didn't get a UITableView.'
*** First throw call stack:
(0x15d3052 0x1764d0a 0x157ba78 0x157b9e9 0x2536ae 0xea5cb 0xf358c 0xee3e8 0x307cc5 0xf1427 0xf158c 0xb6f5280 0xf15cc 0x4546b6 0x448e30 0x15d4ec9 0x275c2 0x2755a 0xccb76 0xcd03f 0xcc2fe 0x4ca30 0x4cc56 0x33384 0x26aa9 0x14bdfa9 0x15a71c5 0x150c022 0x150a90a 0x1509db4 0x1509ccb 0x14bc879 0x14bc93e 0x24a9b 0x1d42 0x1cb5)
terminate called throwing an exception
Here is the code for my table view:
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [self.menu count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell =[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = [[self.menu objectAtIndex:indexPath.row]objectForKey:#"Title"];
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *__strong)indexPath {
DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:#"detailViewController"bundle:nil];
OrderViewController *orderViewController = [[OrderViewController alloc] initWithNibName:#"orderViewController"bundle:nil];
detailViewController.item = [self.menu objectAtIndex:indexPath.row];
orderViewController.itemString = [self.menu objectAtIndex:indexPath.row];
[self.navigationController pushViewController:detailViewController animated:YES];
}
I have seen same problem as mentioned by Hot Licks. My xib file got corrupted. You can define corruption of xib as for example, a control is wired to more than one actions, or wired with couple of ivars. Obviously, by mistake.
Fastest thing to check your xib file,right click on control and see whether it has more than one association.
Related
I'm having some issues with a crash occurring when I change view controllers - Basically I have a VC that takes data from the user for a search - it then brings up a new VC with search results, displayed in a UITableView (not using a UITableViewController, just a TableView inside a regular UIViewController)
Crash Log:
2016-08-29 20:48:03.950 MyApp[2596:60877] *** Assertion failure in -[SearchResultsTable _configureCellForDisplay:forIndexPath:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3512.60.7/UITableView.m:7971
2016-08-29 20:48:03.961 MyApp[2596:60877] Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView (; layer = ; contentOffset: {0, 0}; contentSize: {375, 1128}>) failed to obtain a cell from its dataSource (; layer = ; contentOffset: {0, 0}; contentSize: {0, 0}>)'
*** First throw call stack:
I've read that this issue is caused by not returning a cell in your cellForRowAtIndexPath function, however i'm positive that my implementation will return a cell successfully. (I tested the code of the function somewhere else, and cell does in fact have a value, and is not nil.)
Code:
#property searchResultCell * cell;
-(UITableViewCell*)cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
_cell = [self dequeueReusableCellWithIdentifier:#"cell" forIndexPath:indexPath];
if (_cell == nil)
{
_cell = [[searchResultCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"cell"];
}
[[_cell txtDate] setText:#"test"];
return _cell;
}
Having placed some breakpoints down, it appears that this section of code is never even executed, despite the UITableView class, delegate and dataSource being set correctly.
viewDidLoad for the Search Results VC ([self SpecifiedSerial] is set previously before the segue happens. It is an NSString*):
- (void)viewDidLoad
{
[super viewDidLoad];
_SearchResultsTableDelegate = [[searchResultsTable alloc] init:[self specifiedSerial]];
[[self SearchResultsTable] setDelegate:_SearchResultsTableDelegate];
[[self SearchResultsTable] setDataSource:_SearchResultsTableDelegate];
}
Declarations:
#property (weak, nonatomic) IBOutlet UITableView *SearchResultsTable;
#property searchResultsTable * SearchResultsTableDelegate;
If anyone could point me in the right direction here, it'd be much appreciated!
Use this code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
_cell = [tableView dequeueReusableCellWithIdentifier:#"cell" forIndexPath:indexPath];
Instead of:
-(UITableViewCell*)cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
_cell = [self dequeueReusableCellWithIdentifier:#"cell" forIndexPath:indexPath];
Edit:
Your numberOfRowsInSection and numberOfSectionsInTableView seems to be incorrect.
Try this code:
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [[self searchedTrainSightings] count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
_cell = [tableView dequeueReusableCellWithIdentifier:#"MyCell" forIndexPath:indexPath];
if (_cell == nil)
{
_cell = [[MyCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"cell"];
}
[[_cell textLabel] setText:#"test"];
return _cell;
}
probably the reason is you are returning nil from cellForRowAtIndexPath method and failing to dequeue a reusable cell.
use code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
searchResultCell *cell;
cell = (searchResultCell *)[tableView dequeueReusableCellWithIdentifier:#"cell"];
if (cell == nil){
cell = [[searchResultCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"cell"];
}
[[_cell txtDate] setText:#"test"];
return cell;
}
And just configure your cell selecting your custom cell giving cell identifier using storyboard see image.
Hope it helps.
I seriously doubt the delegate method which you are using. I have seen this version of cellForRowAtIndexPath method
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
Try this
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
_cell = [tableView dequeueReusableCellWithIdentifier:#"Cell"];
if (_cell == nil)
{
_cell = [[searchResultCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"cell"];
}
[[_cell txtDate] setText:#"test"];
return _cell;
}
My app crashes when I try to insert a new entry. I received this error previously, and I was not able to fix it. Can anyone help?
Here is my error displayed in the console:
2013-09-14 15:41:00.370 Probation App[9919:907] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 2 beyond bounds [0 .. 1]'
*** First throw call stack:
(0x31fe82a3 0x39ccc97f 0x31f33b75 0xd7b81 0x33eb228d 0x33f34f81 0x328f6277 0x31fbd5df 0x31fbd291 0x31fbbf01 0x31f2eebd 0x31f2ed49 0x35af62eb 0x33e44301 0x542fd 0x3a103b20)
libc++abi.dylib: terminate called throwing an exception
and here is my code:
#pragma mark UITableViewDataSource Methods
- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tv dequeueReusableCellWithIdentifier:#"cell"];
if( nil == cell)
{
cell = [[UITableViewCell alloc] initWithStyle: UITableViewCellStyleSubtitle reuseIdentifier:#"cell"];
}
if (indexPath.row <self.probationers.count)
{
Probationer *thisProbationer = [self.probationers objectAtIndex:indexPath.row];
cell.textLabel.text = thisProbationer.probationerName;
cell.detailTextLabel.text = thisProbationer.probationerID;
}
else
{
cell.textLabel.text = #"Add Probationer";
cell.textLabel.textColor = [UIColor lightGrayColor];
cell.editingAccessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
return cell;
}
-(NSInteger)tableView: (UITableView *)tv numberOfRowsInSection:(NSInteger)section
{
NSInteger count = self.probationers.count;
if(self.editing)
{
count = count +1;
}
return count;
//return [self.probationers count];
}
//Deleting an Entry
-(void) tableView:(UITableView *)tv commitEditingStyle:(UITableViewCellEditingStyle) editing forRowAtIndexPath: (NSIndexPath *) indexPath
{
if (editing == UITableViewCellEditingStyleDelete)
{
[self.probationers removeObjectAtIndex:indexPath.row];
[tv deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft];
}
}
#pragma mark UITableViewDelegate Methods
-(void)tableView:(UITableView *)tv didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
Probationer *chosenProbationer = [self.probationers objectAtIndex:indexPath.row];
ProbationerController *detailedViewController = [[ProbationerController alloc]init];
detailedViewController.delegate = self;
detailedViewController.currentProbationer = chosenProbationer;
if (indexPath.row <self.probationers.count && !self.editing)
{
[self.navigationController pushViewController:detailedViewController animated:YES];
}
if (indexPath.row == self.probationers.count && self.editing)
{
AddProbationerController *addProbationer = [[AddProbationerController alloc] init];
[self.navigationController pushViewController:addProbationer animated:YES];
}
[tv deselectRowAtIndexPath:indexPath animated:YES];
//selectedIndexPath = indexPath;
//[self.navigationController pushViewController:detailedViewController animated:YES];
}
The number of rows should always come from the data source (the bit you have commented out //return [self.probationers count];). Don't try to just add to the number. Add to the data source and then refresh the table view.
The stack trace say it all. Its definitely because of you self.probationers array.
Why don't you NSLog the number of items in the array and the number of rows/sections in your tableview.
When you are trying to associate indexPath.row and self.probationers you have to make sure they match with number of elements.
Also follow the basics while accessing elements of array(as they are much prone to get exceptions)
Nil check for the accessing array.
Know the exact count of the array, by logging.
Make sure you are trying to access any objects more than the available array indexes.
I sometimes get a crash with this error [UIMutableIndexPath release]: message sent to deallocated instance 0x205a2930 when I try to execute :
[self.detailsTableView reloadData];
The cellForRowAtIndexPath method is here :
- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
DetailResultCell *cell = (DetailResultCell*) [aTableView dequeueReusableCellWithIdentifier:DETAIL_RESULT_CELL_ID];
if(cell == nil)
{
[[NSBundle mainBundle]loadNibNamed:DETAIL_RESULT_CELL_ID owner:self options:nil];
cell = detailResultCell;
}
cell.detailsResultatViagerViewController = self;
[cell cellWithIndexPath:indexPath andChamp:[[self.resultats objectAtIndex:indexPath.section] objectAtIndex:indexPath.row]];
return cell;
}
How can I avoid this ? I try to put a try/catch block around the [self.detailsTableView reloadData]; but the crash still happens...
I'm trying to learn table views and I've hit a snag. I have the view delegate and datasource connected correctly in Storyboard, but I get the following runtime error when I get to the section of my app containing the table view.
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UINavigationItem tableView:numberOfRowsInSection:]: unrecognized selector sent to instance
Here's the chunk from my implementation file
#implementation CraftingViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 5;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = (UITableViewCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = #"Detail";
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
}
That error message is displaying because tableView:numberOfRowsInSection: is being sent to an object of type UINavigationItem while it seems like your CraftingViewController class is probably of type UITableViewController. I would make sure that you have connected your delegate to the correct class, because it doesn't seem like CraftingViewController is connected properly.
if the datasource is controller of the nib file.
please check alloc of this controller use "CraftingViewController" not "UIViewController"
Newbie question here ...
I've created a Master-Detail Application project in Xcode 4.2 using ARC and Storyboard. I've modified the template to be:
MasterViewController.h
#import <UIKit/UIKit.h>
#class DetailViewController;
#interface MasterViewController : UITableViewController
{
NSMutableArray *items;
}
#property (strong, nonatomic) DetailViewController *detailViewController;
#property (strong, nonatomic) NSMutableArray *items;
#end
MasterViewController.m (snipits)
....
#synthesize items;
....
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.detailViewController = (DetailViewController)[[self.splitViewController.viewControllers lastObject] topViewController];
items = [[NSMutableArray alloc] initWithObjects:#"item 1", #"item 2", nil];
[self.tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:NO scrollPosition:UITableViewScrollPositionMiddle];
}
....
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [items count];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return #"Test Section";
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// Configure the cell.
cell.textLabel.text = [items objectAtIndex:indexPath.row];
return cell;
}
This code will fail on this line when the program runs:
[self.tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:NO scrollPosition:UITableViewScrollPositionMiddle];
with this exception:
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 1 beyond bounds [0 .. 0]'
If I cut the list(items) down to a single item, the MasterViewController will load without errors. I'm obviously doing something wrong, but I can't for the life of me figure out what it is. Anyone care to point out the obvious for me?
The template includes a UITableView that is set up for static cells. And it's actually one static cell. (this is why making your array one item long happens to kind of work)
But it seems you don't want static content here. So you just have to go into the storyboard, select the UITableView, go to the Attributes Inspector, and change the Content type to Dynamic Prototypes.
That should get you past this issue.
EDIT
A somewhat related issue is that you probably also want to use the prototype cell in the storyboard. To do that, just set the cell identifier of that prototype to the cell identifier you are using in your tableView:cellForRowAtIndexPath:.
And then omit the whole 'if (cell==nil)' part. The cell won't be nil.
So that method will look like this now:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell"; // <-- Make sure this matches what you have in the storyboard
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// Configure the cell.
cell.textLabel.text = [self.items objectAtIndex:indexPath.row];
return cell;
}
Hope that helps.