I have a problem with prepareForSegue method. I need to pass NSString from one view to another but all I get is:
2013-08-13 12:13:45.765 DailyPhotos[12551:907] -[ArchiveViewController textLabel]: unrecognized selector sent to instance 0x1e5592f0
2013-08-13 12:13:45.775 DailyPhotos[12551:907] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ArchiveViewController textLabel]: unrecognized selector sent to instance 0x1e5592f0'
*** First throw call stack:
(0x328852a3 0x3a52a97f 0x32888e07 0x32887531 0x327def68 0x813dd 0x34a1ade9 0x8174d 0x3474f28d 0x347d1f81 0x33193277 0x3285a5df 0x3285a291 0x32858f01 0x327cbebd 0x327cbd49 0x3638f2eb 0x346e1301 0x78fb9 0x3a961b20)
libc++abi.dylib: terminate called throwing an exception
Here is my prepareForSegue implementation:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Checking the segue to perform
if ([[segue identifier] isEqualToString:#"projectDetailsSegue"]) {
AlbumViewController *destinationView = [segue destinationViewController];
// Creating variable with selected cell
UITableViewCell *selectedCell = (UITableViewCell *)sender;
// Passing the cell title to destination cell
destinationView.projectTitle = #"tmp";
NSLog(#"%#", selectedCell.textLabel.text);
}
}
For now I'm passing #"tmp" and it works but when I try to pass anything connected with selectedCell it crashes. Why is this happening? How can I reapir this problem?
You are using the sender to get your selectedCell.
But as you can see in the error, your sender is not an UITableViewCell, but an ArchiveViewController. Probably because you are doing a:
[self performSegueWithIdentifier:#"projectDetailsSegue" sender:self];
What you should be doing is:
[self performSegueWithIdentifier:#"projectDetailsSegue" sender:*yourCell*];
Related
I'm trying to pass data from my ViewController to TabBarController by using Objective-C. I'm trying to assign some data to "bottomTabEventList" (which is a property of my custom TabBarController class). Unfortunately, my program crashes by giving unrecognized selector instance error/warning.
In custom header of TabBarController class, named BottomTabview:
#interface BottomTabView : UITabBarController <UITabBarControllerDelegate>
#property(strong,nonatomic)EventList *bottomTabEventList;
#end
And prepareForSegue method in ViewController.m
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
BottomTabView *btw = [segue destinationViewController];
//checking
if(btw == nil)
NSLog(#"btw in viewController is nil");
else
NSLog(#"btw in viewController is NOT nil");
if(self.eventList.eventList == nil)
NSLog(#"eventList in viewController is nil");
else
NSLog(#"eventList in viewController is NOT nil"); //end of checking
btw.bottomTabEventList = self.eventList; //This is where crash appears
}
Exact crash log is:
-[ViewController setBottomTabEventList:]: unrecognized selector sent to instance 0x7fe923c6ba00
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ViewController setBottomTabEventList:]: unrecognized selector sent to instance 0x7fe923c6ba00'
Segue is from ViewController to BottomTabView and its type is "Present Modally". I'd really appreciate if you can help/guide me. Thanks in advance.
The problem seems to be that btw is not actually of type BottomTabView and is just a UIViewController hence the crash log giving:
[ViewController setBottomTabEventList:]: unrecognized selector sent to instance
As UIViewController does't know what BottomTabEventList is.
You need to make sure that btw is actually a BottomTabView instance.
Do a little introspection and I bet it will not go into this statement:
if ([btw isKindOfClass:[BottomTabView class]]){
btw.bottomTabEventList = self.eventList;
}
I'm getting the following error when trying to set a string in a public property in prepare for segue. Any idea why?
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController setQuestionObjectId:]: unrecognized selector sent to instance 0x7fa713562b40'
The code is:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:#"postSegue"]) {
CommentsViewControllerNew *commentsVC = (CommentsViewControllerNew *)[segue destinationViewController];
commentsVC.hidesBottomBarWhenPushed = YES;
PFObject * question=[self.brightenArray objectAtIndex:self.indexPathOfClickedpost.row];
commentsVC.questionObjectId=question.objectId;
NSLog(#"%#",[self.Array objectAtIndex:self.indexPathOfClickedpost.row]);
// commentsVC.question = question;
As you may have already gathered, this is caused because you are sending a setQuestionObjectId: message to a class that doesn't recognise that message. E.g. if you send a reloadData (from UITableView) message to an NSString then you will get a similar exception. This is because NSString doesn't implement (have a method) called reloadData.
This error often happens in the prepareForSegue:sender: method because you are typecasting a UIViewController to a custom subclass (in this case CommentsViewControllerNew). The typecasting happens on this line:
CommentsViewControllerNew *commentsVC = (CommentsViewControllerNew *)[segue destinationViewController];
You are essentially telling the compiler: Yes I know that you think this is a UIViewController but it's actually a CommentsViewControllerNew. The crash comes because, in this case the compiler is right, it is a UIViewController and UIViewController doesn't have a method or property name called questionObjectID
After that long explanation... The fix is to go to your Interface Builder, select the relevant view controller and set its class as CommentsViewControllerNew.
NOTE: If you don't understand, or are unfamiliar with any of what I'm talking about, I suggest you do some reading or do a few tutorials. There are loads of good ones on YouTube.
I have a collectionview but when i tried to click the image the it showing this error ? The whole application is a tabbar application ,so all other tabs are working . except the last tab images.
iam taking images from plist for displaying it into collectionview
this is error
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI
objectAtIndex:]: index 0 beyond bounds for empty array'*** First throw call stack: (0x1e92012
0x1969e7e 0x1e47b44 0x58b91 0x56686 0x137cf 0x98f1c7 0x98f232 0x98f4da 0x9a68e5 0x9a69cb 0x9a6c76
`0x9a6d71 0x9a789b 0x9a7e93 0x9a7a88 0xd03e63 0xcf5b99 0xcf5c14 0xdaf5d9 0xdc1182 0xdc1394 0x197d705
0x9bb93c 0x9bb9ac 0x197d705 0x9bb93c 0x9bb9ac 0xb751d3 0x1e5aafe 0x1e5aa3d 0x1e387c2 0x1e37f44
0x1e37e1b 0x3c0f7e3 0x3c0f668 0x8adffc 0x287d 0x27a5) libc++abi.dylib: terminate called throwing an exception
This is the didselect method and preparesegue for passing that array to another viewcontroller
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:#"bookItem"]) {
NSDictionary *currentBook = [[_freeBooks objectForKey:#"freebook"] objectAtIndex:[[[self.collectionView indexPathsForSelectedItems] objectAtIndex:0] row]];
NSLog(#"%#", currentBook);
GMMDetailpage *detailpage = (GMMDetailpage *)[segue destinationViewController];
detailpage.bookDetails = currentBook;
NSLog(#"%#",detailpage.bookDetails);
}
}
The value of current book is printing and its fine.... but after this it executes some other system codes and then it shows exception .check image
You are doing two array accesses, so the error comes from the fact that one of the two arrays is empty.
The two arrays are
[self.collectionView indexPathsForSelectedItems]
and
[_freeBooks objectForKey:#"freebook"]
Check both the array independently and find out which one is the empty one.
I'm trying to create this application, when you press on a tablecell you get shown the ViewController, and the variable get's set in the other view controller. Although i'm getting a few errors when i press the uitablecell.
Error:
2013-04-06 22:47:25.970 iFSX Guide[1069:907] Called
2013-04-06 22:47:26.009 iFSX Guide[1069:907] -[__NSCFString _isAncestorOfFirstResponder]: unrecognized selector sent to instance 0x1d562390
2013-04-06 22:47:26.016 iFSX Guide[1069:907] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString _isAncestorOfFirstResponder]: unrecognized selector sent to instance 0x1d562390'
*** First throw call stack:
(0x319b22a3 0x3964c97f 0x319b5e07 0x319b4531 0x3190bf68 0x33832beb 0x338a837f 0x338548fb 0x33a95619 0x338a79b9 0x338a5fe7 0x339c83ef 0xa22a5 0x3387c28d 0x338fef81 0x322c0277 0x319875df 0x31987291 0x31985f01 0x318f8ebd 0x318f8d49 0x354ba2eb 0x3380e301 0xa19d1 0x39a83b20)
libc++abi.dylib: terminate called throwing an exception
The code:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)in dexPath{
NSLog(#"Called");
Aircraft = indexPath.row;
[self performSegueWithIdentifier:#"ToSections" sender:self];
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([segue.identifier isEqualToString:#"ToSections"]){
AirplaneSections *sections = (AirplaneSections *)segue.destinationViewController;
sections.plane = Aircraft;
}
}
I've found out that it's an error on ViewDidLoad on the viewcontroller.
NSString *quickTemp = [NSString alloc];
switch (plane) {
case 0:
quickTemp = #"Boeing 737-800";
break;
default:
break;
}
TitleLabel.text = quickTemp;
*/
I'm doing something wrong there.
Are you using ARC? This sort of problem usually indicates there's a memory error somewhere. Basically, some code somewhere is trying to access an object that was already released. This makes everything go kaboom.
If you aren't using ARC, you should turn it on.
After that, the next thing you should do is run the static analyzer. Fix anything that comes up.
If that doesn't fix the problem, in Xcode, add a breakpoint that stops when an Objective-C exception is thrown. It should show you where exactly this problem is happening.
If that doesn't help, run your code under Instruments' and the Zombie tool. This will show you exactly where you tried to access memory that was already released.
I hope someone can help with this.
I have a UITableViewController and want to pass a value to a UIViewController called NewsArticleViewController when the tablecell is selected. I've created a segue from the tablecell to the view controller.
When I call my prepareForSegue method below:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([[segue identifier] isEqualToString:#"ShowNewsArticle"])
{
NSIndexPath *indexPath = [self._tableView indexPathForSelectedRow];
NSDictionary *article = [_articles objectAtIndex:indexPath.row];
NSString *articleID = [article valueForKey:#"id"];
NSLog(#"Trying %#", articleID);
NewsArticleViewController *detailViewController = [segue destinationViewController];
detailViewController.articleID = articleID;
}
}
The NSLog shows the NSString value correctly before the error occurs on the last line.
I get the error:
2012-12-11 23:08:41.915 My School[4689:c07] -[UIViewController setArticleID:]: unrecognized selector sent to instance 0x8088140
2012-12-11 23:08:41.916 My School[4689:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController setArticleID:]: unrecognized selector sent to instance 0x8088140'
*** First throw call stack:
(0x1800012 0x11c5e7e 0x188b4bd 0x17efbbc 0x17ef94e 0x3ca1 0x554ac7 0x554b54 0x1bc899 0x1bcb3d 0xbc3e83 0x17bf376 0x17bee06 0x17a6a82 0x17a5f44 0x17a5e1b 0x1cc87e3 0x1cc8668 0x10d65c 0x1f4d 0x1e75 0x1)
libc++abi.dylib: terminate called throwing an exception
On the destination view controller, NewsArticleViewController, I have declared this in the header:
#property(strong,nonatomic) id articleID;
And I have synthesized the property in the method. I'm using ARC, I don't know if this is the specific cause but I can't proceed until I sort this out. Thanks.
In your error message, UIViewController is reporting the "unrecognized selector" error. I suspect your storyboard has not specified your custom NewsArticleViewController for this scene. Thus, it's using the default UIViewController which obviously doesn't understand the setArticleID.
Check the "Custom Class" setting for the view controller in Interface Builder:
If the custom class has not specified, it will look like the above screen snapshot. Just fill in the class name.