ios UITableView Crash with Custom Container View Controller - ios

In my storyboard I have 2 views one master and one detail with list. I want to show detail view on master. When I add detail to master like that:
- (void)viewDidLoad
{
[super viewDidLoad];
tableViewController = [[TableViewController alloc] init];
[self addChildViewController:detailVC];
[self.view addSubview:detailVC.view];
}
I get crash like that:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'
Im sure that there is everything ok with my table viewController becouse when I set it to rootViewController there is everything ok. What I'm doing wrong?

Looks like its an issue with tableview delegate methods. In story board please use static cell for your table view controller and remove table view delegate methods or else implement all required table view delegate methods.

Related

Why do I keep getting this error when going from ViewController to TableViewController?

I have this button in my viewController and when I press on it, it should go to the TableViewController. When I do this the app crashes and prints this error in the console. Can someone tell me what Im doing wrong? Thank you!
Terminating app due to uncaught exception 'NSInternalInconsistencyException',
reason: '-[UITableViewController loadView] instantiated view controller with
identifier "UIViewController-iLh-Fe-Ezq" from storyboard "Main", but didn't
get a UITableView.'
When I got this error, I had initially used the boilerplate code for the class UITableViewController, but the actual view controller was a UIViewController.
Original code (resulting in the error):
Note that this is connected to a UIViewController in Storyboard.
class MainViewController: UITableViewController {
//insert rest of code here
//note that funcs such as numberOfRowsInSection(_:) will have the override keyword
}
Working code (removing the error):
class MainViewController: UIViewController {
//insert code here
//you also must *remove the override keywords* for
// some of the included functions or you will get errors
}
Remember also to reference an IBOutlet for your UITableView in your view controller, and set the delegate and datasource (in Storyboard, you Ctrl+Drag from the UITableView to the yellow circle at the top of the view controller, and click dataSource. Repeat this for the delegate as well).
I got it to work....I used a table view controller without the view controller and embedded a navigation controller.

UITableView Delegate in Sub Viewcontroller

I have a UIViewController call Parent, and I have a UIView subview within Parent. I want to add one of two different possible UIViewControllers, called A and B, as subviews of Parent. A is a UIViewController with a UITableView. I set the datasource and delegate of the UITableView in A to A.
I can then "successfully" add A to Parent, setting the data for A as follows:
AViewController *vc = (AViewController *)[self.storyboard instantiateViewControllerWithIdentifier:#"A"];
NSMutableArray *data = [#[#"foo",#"bar",#"baz"] mutableCopy];
vc.posts = data;
[self.container addSubview:vc.view];
By successful, I mean that I see the tableview with the correct data in the cells. Namely foo, bar, and baz as the rows.
My Problem: When I try to scroll the tableview, it crashes. When I try to select a cell, I get the following exception:
Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: '-[_UIAppearanceCustomizableClassInfo
tableView:didSelectRowAtIndexPath:]: unrecognized selector sent to instance 0x78c64430'
Because the AViewController is declared locally in your code above, it is deallocated as soon as that code completes. So when you touch for scrolling/selection and the delegate/datasource methods are called, the delegate and datasource point to a completely different object (or none at all). Hence your crash.
Furthermore, when implementing customer container views you need to implement some code so both parent and child know. Take a look at "Implementing a Custom Container View Controller" in the Apple Docs:
[self addChildViewController:vc];
[self.container addSubview:vc.view];
[vc didMoveToParentViewController:self];
I believe the addChildViewController will also provide a strong reference from the parent to the child (vc), thereby preventing it from being deallocated. So the above code should fix the deallocation problem as well.

error "has no segue with identifier" adding split ViewController

I'm adding a split ViewController with the table view and detail view:
The tableview works fine the cell are been populated and everything but when one of the cells is been selected I get the error:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Receiver (<masterViewController: 0x15ce0e9b0>) has no segue with identifier 'detailView''
Here is my code:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self performSegueWithIdentifier:#"detailView" sender:[_arrayOfFiles objectAtIndex:indexPath.row]];
}
Here is the info of the detailView:
I add identifier to the storyboard segue:
but now I'm getting the following error:
* Terminating app due to uncaught exception 'NSGenericException', reason: 'Could not find a navigation controller for segue 'show tableVIew'. Push segues can only be used when the source controller is managed by an instance of UINavigationController.'
* First throw call stack:
You need to set the identifier for the segue, not the viewController. If you click on the line joining the two viewControllers, you can then set the attributes for the segue in the attributes inspector:
If I'm not wrong you should be adding a Navigation Controller to bot the Master and Detail View Controllers.
Additionally, for a split controller to function it must be set as the root controller.
Good luck!

starting a table view controller

I am trying to push a table view controller that I have on my storyboard from a view controller that I don't have in my storyboard. I get these errors when i get to initializing the first table view cell. I've made sure the table view controller and the table view cell are set to the correct class types that I've defined and I've set the correct identifier for the cell.
Error Occurs at Line:
CustomTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"ListPrototypeCell" forIndexPath:indexPath];
Error:
*** Assertion failure in -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:], /SourceCache/UIKit_Sim/UIKit-2935.137/UITableView.m:5439
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'unable to dequeue a cell with identifier ListPrototypeCell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'
What am I missing?
P.S that other link does not have the answer, I need to initialize multiple cells of this type, I need the index for different data.
Why not just put all the view controllers in one storyboard?
If you're trying to push from a UITableViewCell, you could use a segue method.
First: Control-Drag from your TableViewController to your ViewController to link them with a push segue. Name the segue. E.G. "segueName"
Create a prepareForSegue method like so:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:#"segueName"])
{
// do whatever you want here
}
and then under your didSelectRowAtIndexPath:, run the segue using this:
[self performSegueWithIdentifier:#"segueName" sender:nil];
Perhaps you could elaborate a bit more, if this does not work.

Two split view controllers in a tab bar controller causes crash

My app requires two separate split view controllers. First I created first split view controller that works fine , now added second split view controller but second split view controller causes crash.
in first split's master:
#property (nonatomic,strong) WODTutorialDetailsView *wods;
- (void)viewDidLoad
{
[super viewDidLoad];
//init detail instance
self.wods= (WODTutorialDetailsView *)[[self.splitViewController.viewControllers lastObject] topViewController];
[self populateTableview];
self.navigationItem.title = #"WODs";
}
in second split's master:
#property (nonatomic,strong) LogDetailViewController *wods;
- (void)viewDidLoad
{
[super viewDidLoad];
//init detail instance
self.wods= (LogDetailViewController *)[[self.splitViewController.viewControllers lastObject] topViewController];
[self populateTableview];
self.navigationItem.title = #"WODs";
}
Error I get is:
-[LogDetailViewController topViewController]: unrecognized selector sent to instance 0x229c4f40
2013-02-01 15:12:10.625 WOD Log[2473:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[LogDetailViewController topViewController]:
How can I make it work?
I have never heard of a good rational for this but Apple does say that a UISplitViewController should be the topmost UI Controller. Although this project is a bit old, its description is pretty clear in what it does:
Custom UISplitView which can be used with navigation based project.
Take a look:
https://github.com/palaniraja/cUISplitViewController

Resources