How to segue from a custom delegate and datasource - objective-c

I have a view with 2 tableviews in it. This view has the controller PlayerDetailController
Now to control the 2 tableviews I have 2 other controllers.
tablePlayersDataSourceDelegate
tablePlayerNewsDataSourceDelegate
I ctrl-dragged from the PlayerDetail view to the newsView to make a segue. In my tablePlayerDataSourceDelegate I've the following methods to preform this segue.
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self performSegueWithIdentifier:#"showPlayerDetailNews" sender:indexPath];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
NSIndexPath *indexPath = (NSIndexPath *)sender;
PlayerNews *news = [_tableSource objectAtIndex:indexPath.row]; // ask NSFRC for the NSMO at the row in question
if ([segue.identifier isEqualToString:#"show detail"]) {
[segue.destinationViewController setImageURL:[NSURL URLWithString:news.image]];
[segue.destinationViewController setNewsTitle:news.title];
[segue.destinationViewController setNewsDescription:news.content];
[segue.destinationViewController setNewsCopy:news.image_copyright];
[segue.destinationViewController setNewsUrl:news.url];
[segue.destinationViewController setNewsShortDescription:news.summary];
}
}
But when I test I get the following error.
** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Receiver (<tblPlayerNewsDatasourceDelagete: 0x1e5e44c0>) has no segue with identifier 'showPlayerDetailNews''
I get why this is giving the error. Because the playerDetail view uses the class playerDetailController and I am trying to do te segue in the tablePlayerNewsDelegate class. Do you maybe know a way to work around it?
EDIT
Here you see a picture of what I am talking about
So you can see the two tableviews in the playerDetailView. When a cell in the bottom tableview is clicked it should go to the next view.
EDIT2
This is what I do in my playerDetailController to fill up my tableview. I've put this in my viewDidLoad.
tabelPlayerNews=[[tblPlayerNewsDatasourceDelagete alloc]init];
[tabelPlayerNews setTableSource:_newsArray];
tblNews.dataSource=tabelPlayerNews;
tblNews.delegate=tabelPlayerNews;
tabelPlayerNews.view=tabelPlayerNews.tableView;

I'm not sure whether I understand that or not but in general....
To use performSegueWithIdentifier: the drag for the segue should start at the controller that will make the call, not at a view or other object. I think that's what the error message is telling you: assuming there's a segue called "showPlayerDetailNews" in your storyboard, it doesn't belong to the correct object.

Related

tableView segue after clicking cell is not recognized

I have a tableViewController and when a cell is clicked, I want to record the name of the cell and pass it to a new QuestionViewController programatically. The problem I'm getting is that when the cell is clicked, I get an error:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Receiver () has no segue with identifier 'segueToViewController''
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
self.name = [self.listOfNames objectAtIndex:indexPath.row];
NSLog(#"selected cell: %i, %#", (int)indexPath.row, self.listOfNames);
[self performSegueWithIdentifier:#"segueToViewController" sender:self];
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
NSLog(#"prepare for segue: %#", segue.identifier);
if ([[segue identifier] isEqualToString:#"segueToViewController"]){
QuestionViewController *QVC = segue.destinationViewController;
QVC.currentResidentName = [[NSString alloc] initWithString:self.name];
}
}
Any idea how to make the segue work? I'm not sure why prepareForSegue is not able to identify the segue.
NSLog prints:
selected cell: 0, 123456789
which is good, but it doesn't get to the "prepare for segue" NSLog. When I debug the problem, it crashes right at prepareForSegue
Can you confirm that the segue exists in your storyboard? Even if triggered programatically the segue must exist in your storyboard as described here.
If the segue does exist, check for typos in its name. The name must be spelled the same way in your storyboard and in your code. (This has been a common source of bugs for me, and it seems there is no mechanism for ensuring that storyboard identifiers match the source code.)
If the segue exists and is spelled correctly, then this Stack Overflow thread points at other solutions for more exotic cases, such as projects with multiple storyboards. Also try doing a clean build as suggested in that thread.

segue from TableView

I'm currently learning objective c and i'm trying to create a segue from a table view to a another view. and the code crashes at the prepareForSegue function.
heres the code
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if( [segue.identifier isEqualToString:#"rowSelected"]){
UIViewController *nextViewController = segue.destinationViewController;
nextViewController.title = #"newView";
}
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self performSegueWithIdentifier:#"rowSelected" sender:self];
}
My understanding for prepare for segue is that i initialize the next view there(?). but most tutorials i looked at only set a few configurations inside prepareForSegue.
is there anything obvious that im doing wrong? or perhaps someone can link a tableview + segue guide so i can follow through and find what i did wrong myself.
heres the error message, at least the part that i found to actually contain information
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[notesViewController length]: unrecognized selector sent to class 0x469c'
Hello Pita try this code
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if( [segue.identifier isEqualToString:#"rowSelected"]){
UIViewController *nextViewController = segue.destinationViewController;
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
nextViewController.title = [YourSomethingArray objectAtIndex: indexPath.row];
}
Where yourSomethingArray find above from your code
cell.textLabel.text = yourSomethingArray[indexPath.row];

Storyboard UIViewController not appear

I recently started using storyboard.
I have the main viewcontroller, which by code must call another viewcontroller.
in storyboard, I created a "segue" that goes from the first to the second controller, with the identifier "segueToSignSelection."
in the main viewcontroller, when I need to call up the second viewcontroller, insert this code:
[self performSegueWithIdentifier:#"segueToSignSelection" sender:self];
that calls this method:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([[segue identifier] isEqualToString:#"segueToSignSelection"])
{
signSelectionViewController = (SignSelectionViewController*)[segue destinationViewController];
[self presentModalViewController:segue.destinationViewController animated:YES];
[segue.destinationViewController test];
}
}
in the second controller, the test method is invoked. But the view does not appear. What could be the problem?
Thanks

Objective-C, Storyboard: instantiateViewControllerWithIdentifier returns nil

I have a UITableViewController with a storyboard push segue linking from the prototype cell to a detail page, a regular old UIViewController. In the storyboard, the detail ViewController has an identifier, and the segue has an identifier which is the same as the detail identifier except that the first letter is lowercase. Furthermore, the detail ViewController has a "custom class" (AttractionDetailViewController) selected in the class pulldown.
Doesn't work. The problem is that instantiateViewControllerWithIdentifier:#"AttractionDetails returns nil.
Relevant code. First the prepareForSegue method which the debugger has never entered.
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"attractionDetails"])
{
AttractionDetailViewController *attrDetailVC = [segue destinationViewController];
}
}
Instead it goes into this method:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//AttractionDetailViewController *attrDetailVC = [[AttractionDetailViewController alloc] init];
AttractionDetailViewController *attrDetailVC = [self.storyboard instantiateViewControllerWithIdentifier:#"AttractionDetails"];
NSIndexPath *selIndexPath = [self.tableView indexPathForSelectedRow];
attrDetailVC.theAttraction = [attractions objectAtIndex:indexPath.row];
[self.navigationController pushViewController:attrDetailVC animated:YES];
}
Since instantiateViewControllerWithIdentifier returns nil it throws an exception of course. The really interesting thing is, if I use the alloc init line instead, it works, but the screen is all black.
Anyway, I've read up about this and tried a few different things and I'm still stymied. Does anyone have any suggestions?
The problem is that you didn't instantiate your master view controller (the UITableViewController) from the storyboard, so its storyboard property is nil.

UIWebView on top of UINavigationController stack not shown

I have a UIViewController "PdfViewController" with a view containing an UIScrollView wich is containing an UIWebView, designed by storyboard. I'm using storyboard in Xcode 4.2 with ARC.
If I start PdfViewController as initial ViewController the webview is shown as expected.
I want the PdfViewController to show a PDF from a list of PDF's. So I made a NavigationController containing a TableViewController with the document titles.
If I try to show the PdfViewController by "tableView didSelectRowAtIndexPath" the view stays black and doesn't load the selected document.
There is no errer message from Xcode.
The viewDidLoad and the viewWillAppear from PdfViewController get called.
Here the initialisation of the PdfViewController
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
PdfViewController *pdfViewController = [[PdfViewController alloc]init];
[pdfViewController setFileName:#"test"];
[self.navigationController pushViewController:pdfViewController animated:YES];
}
-It seems, the problem is that the PdfViewController does not load the corrsponding nib by itself.
If I make a seque from the TableViewCell, the PdfViewController is loaded correctly.
I changed the code to:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self.navigationController.viewControllers.lastObject setFileName:#"test"];
}
The only thing to know here, is that the viewDidLoad und viewWillAppear are called before the execution of tableView didSelectRowAtIndexPath, so the PDF has to be loaded in viewDidAppear.
With Xcode 4.2 or later, you can pass the data between two view controllers via segue.
Please Check:
How to pass prepareForSegue: an object
Your code may look like this:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
if ([[segue identifier] isEqualToString:#"__YOUR_SEGUE_STRING__"]) {
PdfViewController *pdfViewController =
(PdfViewController*)[segue destinationViewController];
//
// write your code here
//
[pdfViewController setFileName:#"test"];
}
}