segue.destinationViewController - NSInvalidArgumentException - objective-c

When a user selects a row in UITableViewController, I want to segue to another viewController and set its UIImageView to a previously set image. For now, I am making it generic - always show /images/en.jpeg.
flickrTVC.m (UITableViewController):
#implementation flickrTVC
...
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:#"showPhoto"])
UIImage *photo = [UIImage imageWithContentsOfFile:#"images/en.jpeg"];
[segue.destinationViewController setDisplayedPhoto:photo];
}
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self performSegueWithIdentifier:#"showPhoto" sender:self];
}
I have -(void)setDisplayedPhoto:(UIImage *)image; (it sets self.photo to image) in my photoViewController.h (segue.destinationViewController).
I am getting
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController setDisplayedPhoto:]: unrecognized selector sent to instance 0x1f5c4a60'
on the following line: [segue.destinationViewController setDisplayedPhoto:photo];. Even with the implementation blank, the error still shows up.
I am new to objective-c and, probably, I am just messing some things up.
Any help would be appreciated.
Thanks!

The exception occurs because the object that was there does not define the method setDisplayedPhoto:. This could be because the segue.destinationViewController is currently set to a completely different controller (e.g. for a different view than you think). It could also be that you've defined something similar to that method but not exactly the same; if so then the compiler has probably issued a warning about the setDisplayedPhoto: method call.

Related

Programmatically calling for an action of button results in NSInvalidArgumentException

I have a tableview each cell contains a text and a button. For each button in each cell in cellForRowAtIndexPath I define an action using a selector as such:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
ProductTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"ProductCell" forIndexPath:indexPath];
cell.stateButton.tag = indexPath.row;
[cell.stateButton addTarget:self action:#selector(stateChange:) forControlEvents:UIControlEventTouchUpInside];
/// Rest of code
return cell;
}
At some point in the flow I want to generate an action for all the buttons in my tableview. I do it like that:
#pragma mark - Delegate
- (void)onAllSwitchesStateChange{
for(int i = 0; i < [[SsrDeviceManager instance] ssrDevices].count; i ++){
ProductTableViewCell* cell = (ProductTableViewCell *)[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0]];
UIButton* stateButton = [cell stateButton];
[stateButton performSelector:#selector(stateChange:) withObject:nil];
}
}
This is my selector method:
-(void)stateChange:(UIButton*)sender{
[self.activityIndicator sizeToFit];
[sender addSubview:self.activityIndicator];
[self.activityIndicator startAnimating];
//// Rest of code
}
However, why I try to run this code, I get an error and the app crashes with this message:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIButton stateChange:]: unrecognized selector sent to instance 0x1023686d0'
*** First throw call stack:
(0x233133180 0x23230b9f8 0x23304f9bc 0x25f94c220 0x2331389c8 0x23313a65c 0x101073bdc 0x100fdd844 0x25f922300 0x25f3cb424 0x25f3cb744 0x25f3ca7b0 0x25f9595c4 0x25f95a7ec 0x25f93a85c 0x25fa009d4 0x25fa03100 0x25f9fc330 0x2330c4f1c 0x2330c4e9c 0x2330c4784 0x2330bf6c0 0x2330befb4 0x2352c079c 0x25f920c38 0x10102b794 0x232b828e0)
How can I generate a click action for all buttons at once
"How can I generate a click action for all buttons at once"
The very notion makes no sense. A table view is just view. It lets the user communicate with you (the app) because it is touchable interface, but it is not, in itself, a source of activity; it merely represents the data.
If you want something to happen, it is insane to turn to all your buttons and ask them all to initiate some sort of action. Simply do to your data, yourself, whatever it is that you want done.
UIButton doesn't have a method stateChange:. Your class has a method stateChange:. You could just call your own class's method like [self stateChange:stateButton]. If you want the button to send the message it would send if a particular type of even happened, you could do something like [stateButton sendActionsForControlEvents:UIControlEventTouchUpInside].

Button on click not perform segue method.and occur this type of error

if i am call perform segue method on button click.that this type error occur.
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[bparty setNdetail:]:
unrecognized selector sent to instance 0x17da33c0'
Here is the code:
-(IBAction)btn_serch:(id)sender {
[self performSegueWithIdentifier:#"bparty" sender:self];
}
how to solve..tell me
You need to create a method called prepareForSegue
where bparty is the segue identifier in storyboard
and DetailViewController is the page where u will goto.
also dont forget to import the DetailViewController(viewcontroller in ur .m file)
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
DetailViewController *sendDetails = segue.destinationViewController;
if ([[segue identifier] isEqualToString:#"bparty"])
{
//here ur perfor an action
//ex [self.navigationController pushViewController:sendDetails animated:YES];
}
}

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.

How to segue from a custom delegate and datasource

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.

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];