UITableViewController crashes after cell selected - ios

I have an UITableViewController that Ive pulled out in story board and made a custom UITableViewController class to control it. The table is loaded correctly but when a cell is selected a segue is supposed to be preformed to a ViewController but instead the app crashes and I get this:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UITableViewController loadView] loaded the "lZs-yn-NHN-view-Nia-cR-yrl" nib but didn't get a UITableView.'
The UITableViewController is preceded by a tabViewController and a NavigationController in story board if that is affecting anything. This code runs but after this the app crashes:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:#"DisplayMovieFromAllMovies"]) {
NSIndexPath * indexPath = [self.tableView indexPathForCell:sender];
NSString * sectionHeader = [self.headerArray objectAtIndex:indexPath.section];
NSDictionary * selectedMovieDict = [[self.movieSortedDict objectForKey:sectionHeader] objectAtIndex:indexPath.row];
NSLog(#"selected: %#", [selectedMovieDict objectForKey:#"title"]);
[segue.destinationViewController setMovieDict:selectedMovieDict];
}}
Maybe I wired something incorrectly up in storyboard.

Related

From view controller to PageViewController

i've got a UIViewControllers with two UIButtons, i want to know how to pass from this UIViewController to my UIPageViewController,
i tried to link the UIButton to my UIPageViewController from the storyboard but it gives me this error
Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: 'Storyboard () doesn't contain a view controller with identifier
'Guide''
how should i do?
EDIT
- (IBAction)goToGuide:(id)sender{
[self performSegueWithIdentifier:#"goToGuide" sender:self];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"nextView"])
{
FirstLaunch *fLaunch = [segue destinationViewController];
//pass any data to next view here
}
}
Added this to my UIViewController and added the identifier in my storyboard a connection between the view controller and the UIPageViewController and set the identifier to goToGuide, but same error..
UP
EDIT2
- (IBAction)goToGuide:(id)sender{
[(UINavigationController*)self.window.rootViewController pushViewController:Guide animated:YES];
[self performSegueWithIdentifier:#"NextView" sender:self];
}
It says, property windows not found on object of type FirstLaunch
Give the segue identifer in the storyboard, you must have missed it.
Check this answer
ios automatically segue from one screen to another

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.

Unrecognized selector sent to destinationViewController

UITableView in my app is managed using NSFetchedResultsController and I want to implement Master-Detail behaviour but everytime I tap on a cell I get this -[UIViewController setActivity:]: unrecognized selector sent to instance 0x176a7660 error...
I don't know what is going on because my code is based on Apple's Master-Detail demo app.
Here is prepareForSegue:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"activitySegue"]) {
ActivityDetailsViewController *advc = segue.destinationViewController;
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
Activity *activity = (Activity *)[[self fetchedResultsController] objectAtIndexPath:indexPath];
[advc setActivity:activity];
}
}
And of course, there is declared #property in destinationViewController. I think that there could be something with this NSManagedObject and it is not passed properly to destination... But this is only my guess.
It looks like the name of the view controller class in your storyboard for the detail view controller is not set, so an instance of UIViewController is created instead of an instance of ActivityDetailsViewController.
Set the name of the view controller in the story board to ActivityDetailsViewController.
I think issue in this line
Activity *activity = (Activity *)[[self fetchedResultsController] objectAtIndexPath:indexPath]; Is this returning activity object ?

Passing data from PFQueryForTableViewController cell through segue to viewController

so I am trying to pass data from my cell (populated with queryForTable method) through a segue to another viewController. I am using the prepareForSegue method and my code looks like:
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"profile"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
PFObject *object = [self.objects objectAtIndex:indexPath.row];
//UINavigationController *nav = [segue destinationViewController];
ProfileViewController *userProfile = [segue destinationViewController]; //(ProfileViewController *) nav.topViewController;
userProfile.userInfo = object;
}
}
in my VC I have the property defined:
#property (weak, nonatomic) PFObject *userInfo;
but when I run my code I get the error:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController setUserInfo:]:
It looks like the viewController you're pulling out of the segue isn't a ProfileViewController - the error you're getting states:
-[UIViewController setUserInfo:]:
Note UIViewController, not ProfileViewController. This would seem to indicate that your segue's destination viewController isn't exactly what you think it is.
Check your destination viewController's class in your Storyboard. Is it set to ProfileViewController? Is your ProfileViewController embedded inside another viewController (like a navigationController - looking at your commented out code, you seem to have treated it as such before)? If so, you might need to do a big more digging to get a reference to the correct viewController.

Why is my app crashing when I try to set the value of this variable in prepareForSegue?

The gist of what I'm trying to do is set the value of a label on the window I'm segueing to the text that the user entered on the previous window.
The user segues by clicking "Read", which segues them.
Here's my prepareForSegue method:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
ReadingViewController *destination = segue.destinationViewController;
destination.textToRead = self.textInput.text;
}
textToRead is just an NSString object that holds the text that the user enters. (This text is then set as a label with the viewDidLoad method.)
The window that is segued to is set as a different view controller as expected (ReadingViewController) and I created the segue by control-dragging from the "Read" UIButton to the next window.
I can't seem to figure out what the problem is. Here's the error it gives:
2013-03-13 19:00:08.119 Project Lego[1523:c07] -[UINavigationController setTextToRead:]: unrecognized selector sent to instance 0x894d230
2013-03-13 19:00:08.122 Project Lego[1523:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UINavigationController setTextToRead:]: unrecognized selector sent to instance 0x894d230'
*** First throw call stack:
(0x1c92012 0x10cfe7e 0x1d1d4bd 0x1c81bbc 0x1c8194e 0x2949 0x45bb87 0x45bc14 0x10e3705 0x172c0 0x17258 0xd8021 0xd857f 0xd76e8 0x46cef 0x46f02 0x24d4a 0x16698 0x1beddf9 0x1bedad0 0x1c07bf5 0x1c07962 0x1c38bb6 0x1c37f44 0x1c37e1b 0x1bec7e3 0x1bec668 0x13ffc 0x244d 0x2375 0x1)
libc++abi.dylib: terminate called throwing an exception
(lldb)
If you want to access the view controller embedded in a navigationVC, do something like this:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
UINavigationController *nav = (UINavigationController*)segue.destinationViewController;
ReadingViewController *destination = [nav.viewControllers objectAtIndex:0];
destination.textToRead = self.textInput.text;
}
Your segue is referencing the UINavigationController, not your viewcontroller class. Check your Storyboard to make sure the segue is connecting the right controllers.
You seem to be setting textToRead on the Navigation controller. I am assuming you want to set this in the view controller. If so you need to
if ([segue.destinationViewController
isKindOfClass:[UINavigationController class]])
{
mvc = (ReadingViewController *) [segue.destinationViewController topViewController];
mvc.textToRead = self.textInput.text;
} else {
ReadingViewController *destination = segue.destinationViewController;
destination.textToRead = self.textInput.text;
}

Resources