Terminating app due to uncaught exception, while loading a view - iphone

I am getting this error, while I am trying to load another view
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-
[__NSCFType new1:]: unrecognized selector sent to instance 0x5c27950'
Here new1 is a button, which when pressed loads a view.
And here is the code inside the new1
-(IBAction) new1:(id) sender
{
viewController = [[iTViewController alloc] initWithNibName:#"iTViewController" bundle:[NSBundle mainBundle]];
[self.view addSubview:viewController.view];
}
Note: When I launch the App from fresh and press the new1 button, it works flawlessly, but when I press other button which loads other view and when I return back to this view and press new1, then it crashes

The error * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '- [__NSCFType new1:]: unrecognized selector sent to instance 0x5c27950' may not be coming from inside the - (IBAction)new1:(id)sender method. What that error is saying is that you are trying to call a non-existent method on whatever object is at the address 0x5c27950. Here are a few possible solutions:
Set NSZombieEnabled, malloc stack logging, and guard malloc in the debugger. Then, when your App crashes, type this in the gdb comsole:
(gdb) info malloc-history 0x5c27950
Replace 0x5c27950 with the address of the object that the stack trace says caused the crash,and it will give you a much more useful stack trace and it should highlight the exact line that is causing the problem.
Check out this article for more info on NSZombieEnabled.
This one for MallocStackLogging info
More info on guard malloc here
Also, have you tried pushing the view controller (assuming your using a navigation controller):
- (IBAction)new1:(id)sender {
iTViewController *viewController = [[iTViewController alloc] initWithNibName:#"iTViewController" bundle:nil];
[self.navigationController pushViewController:viewController animated:YES];
[viewController release];
}
Or, if you are not using a nav controller, you can present it modally:
- (IBAction)new1:(id)sender {
iTViewController *viewController = [[iTViewController alloc] initWithNibName:#"iTViewController" bundle:nil];
[self presentModalViewController:viewController animated:YES];
[viewController release];
}
Another possibility is that you are calling [self new1:someButton]; but the method is not declared in your header file like so:
#interface MyViewController: UIViewController {
........
}
- (IBAction)new1:(id)sender;
#end

Related

how can i solve this error : NSInvalidArgumentException', reason: '-[ViewController viewControllers]: unrecognized selector

I want to push some information to a UITableView so i have to get the location of that View.
and this is the code inside the AppDelegate :
player = [[player1Data alloc] init];
player.name = #"Dave Brubeck";
player.game = #"Texas Hold’em Poker";
player.rating = 2;
[playersArray addObject:player];
// to get the player1ViewController
UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController;
UITabBarController *tabBarController = [[navigationController viewControllers] objectAtIndex:0];
player1ViewController *playersViewController = [[tabBarController viewControllers] objectAtIndex:0];
playersViewController.playersArray = playersArray;
return YES;
the error was appearing at :
player1ViewController *playersViewController = [[tabBarController viewControllers] objectAtIndex:0];
then the xcode shows that : Thread 1: signal SIGABRT
the console shows :
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ViewController viewControllers]: unrecognized selector sent to instance 0x687a880'
here is my storyboard layout, i'm not sure if is it the right arrangement.
Navigation Controller→View Controller(with a button)→Tab Bar Controller→Table View(where i want to show the players info.)
So sorry my English is not very well, hoping u guys could understand what i'm talkin about.
THX!!
The initialization part of UITabBarController is the problem.Assigning a viewconroller from navigationcontroller stack to UITabBarController??
Prepare an array of VC that you need to show in UITabBarController and load it to the viewcontrollers property of UITabBarController

Cannot push TTTableViewController onto Navigation Controller

I have an app where I have a TTTableView Controller inside a Navigation Controller that is Insider a TabBar.
I want it so that if a user selects an item it will push another TTTableView with the items under that category.
The code I have is
-(void)didSelectObject:(id)object atIndexPath:(NSIndexPath *)indexPath {
if ([object isKindOfClass:[TTTableMoreButton class]]) {
[super didSelectObject:object atIndexPath:indexPath];
} else {
CategoryViewController *viewController = [[CategoryViewController alloc] initWithNibName:#"CategoryViewController" bundle:nil];
[self.navigationController pushViewController:viewController animated:YES];
[viewController release];
}
}
The CategoryViewController is setup as
#interface CategoryViewController : TTTableViewController
and the CategoryViewController.xib file has the datasource & delegate set to the files owner and the view set to the tableview and the tableview class is set to TTTableView.
When I run it I get the following error when selecting a row
2011-10-17 16:18:23.819 Biz Insider[34067:f803] -[CategoryViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x6c93d30
2011-10-17 16:18:23.820 Biz Insider[34067:f803] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CategoryViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x6c93d30'
*** First throw call stack:
(0x1893052 0x157ed0a 0x1894ced 0x17f9f00 0x17f9ce2 0xb4cf2b 0xb4f722 0x9ff7c7 0x9ff2c1 0x9b61e 0xa0228c 0xa06783 0x9bb48 0x9b1301 0x1894e72 0x89192d 0x89b827 0x821fa7 0x823ea6 0x823580 0x18679ce 0x17fe670 0x17ca4f6 0x17c9db4 0x17c9ccb 0x1f88879 0x1f8893e 0x972a9b 0x273d 0x26b5)
terminate called throwing an exceptionCurrent language: auto; currently objective-c
If I try and push another view (i have one with a webview on it) then it works fine, or if I go into interface builder and link the File Owner's "tableView" to the TTTableView object it will work fine and push the controller except the "Pull down to refresh" function wont work so I am assuming that the deletage isn't correct when doing it that way.
Any help would be greatly appreciated.
EDIT:
I have a feeling that it has something to do with the following
-(id<UITableViewDelegate>)createDelegate {
return [[[TTTableViewDragRefreshDelegate alloc] initWithController:self] autorelease];
}
This sets the delegate to TTTableViewDragRefreshDelegate which implements the numberOfRowsInSection and all that junk. Is there another way to do this?
Cheers,
Dean
The log says that in your custom class CategoryViewController method tableView:numberOfRowsInSection: is not implemented and so it couldn't call it.
Check it and check types of its parameters.
Well this is an odd one, but I changed it from
CategoryViewController *viewController = [[CategoryViewController alloc] initWithNibName:#"CategoryViewController" bundle:nil];
to
CategoryViewController *viewController = [[CategoryViewController alloc] init];
and it magically works now...dont ask me how or why.
There must have been something in the NIB that was messing it up, but I dont know how the whole layout is working now with no NIB.

UIPopover Not Showing, Causing Crash

I'm using this code to show a popover from the toolbar of the detail view of a split view controller.
- (IBAction)showBookmarksMenu:(id)sender
{
BookmarksViewController* content = [[BookmarksViewController alloc] init];//UITableViewController
UIPopoverController* aPopover = [[UIPopoverController alloc] initWithContentViewController:content];
aPopover.delegate = self;
[content release];
// Store the popover in a custom property for later use.
self.popoverController = aPopover;
[aPopover release];
[self.popoverController presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
Getting this crash:
2011-08-16 23:59:55.730 Codes[3646:707] -[DetailViewControlleriPad showBookmarksMenu]: unrecognized selector sent to instance 0x191220
2011-08-16 23:59:55.757 Codes[3646:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[DetailViewControlleriPad showBookmarksMenu]: unrecognized selector sent to instance 0x191220'
The showBookmarksMenu: method is being called on DetailViewControlleriPad, whereas it should be called on the class which implements it.
Ensure that the method is properly hooked in IB.
Your showBookmarksMenu: method is not found by the class and that's why it is crashing your application. Check your source code and try again. Have a happy coding. :)

Strange Objective-C problem

My app has a navigation controller and two views, firstController and secondController.
firstController has a webView that displays an html page with links, and clicking any link will take the user to secondController. This is where the program stops by stepping through the debugger.
See code below.
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
if (navigationType == UIWebViewNavigationTypeLinkClicked) {
secondController *nextController = [[secondController alloc] init];
[self.navigationController pushViewController:nextController animated:YES];
[nextController release];
return NO;
}
return YES;
}
This works fine except for when I navigate from firstController to secondController by clicking any link on firstController the third time, the application just exits.(firstController link click, secondController back button, firstController link click, secondController back button, firstController link click and the application crashes)
Terminating app due to uncaught
exception
'NSInvalidArgumentException', reason:
'*** -[NSCFSet length]: unrecognized
selector sent to instance 0x251f100'
This is so strange. I've tried everything but still couldn't figure out what went wrong.
You have a memory problem, where some object is sent the length message, but that object is long gone and has it's memory occupied by a NSCFSet object. There's the explanation for the error. Now for the bug.
You might want to try not to release nextController so quickly, but wait a little longer; use autorelease so nextController stays alive at least until the moment your app is returning to some idle mode. So:
secondController *nextController = [[[secondController alloc] init] autorelease];
Otherwise, delve into the inner workings of secondController.
Use NSSet count if you want to know how many elements your set has

iPhone SDK: Switching to one view then back to previous view errors

I have a UITabBarConroller that I use to switch between 3 different views. This all works perfectly. On one of my tabs, I added a button at the to called "Add", I have added an outlet to this, as well as an IBAction method which looks like the following:
// Method used to load up view where we can add a new ride
- (IBAction)showAddNewRideView {
MyRidesViewController *controller = [[MyRidesViewController alloc] initWithNibName:#"AddNewRide" bundle:nil];
controller.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:controller animated:YES];
[controller release];
}//end showAddNewRideView
This currently works fine, and loads up my AddNewRide nib file. But, once that view loads, I have a cancel button, which, when clicked, I want to return to the previous view. So, I figured I would just do the reverse of the above, using the following method which would load back my previous nib:
- (IBAction)cancelAddingNewRide {
MyRidesViewController *controller = [[MyRidesViewController alloc] initWithNibName:#"MainWindow" bundle:nil];
controller.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:controller animated:YES];
[controller release];
}//end cancelAddingNewRide
But, which trying to load the MainWindow nib, the program crashes, and I get the following error:
2010-05-05 20:24:37.211 Ride[6032:207] *** -[MyRidesViewController cancelAddingNewRide]: unrecognized selector sent to instance 0x501e450
2010-05-05 20:24:37.213 Ride[6032:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[MyRidesViewController cancelAddingNewRide]: unrecognized selector sent to instance 0x501e450'
So, I am a little lost as to why it would work one way, but not the other.
First, I wanted to address part of the error: Think of your views as a stack. When you "push" a modal controller, you are adding that view to a stack. The old view is still there underneath. So you need to "pop" off the modal view to return to the old view. If you push a new view on, you now have 3 views on the stack which are all taking up memory, where you really only need one.
So, inside cancelAddingNewRide just try:
[super dismissModalViewControllerAnimated:true];
You may have other issues that are causing the crash, but this should generally get things working.
Typically when I have used presentModalViewController the presented viewController tells the calling viewController to dismiss it using dismissModalViewControllerAnimated:YES;
So in other words in the cacncelAddingNewRide you simply call the class that hass showAddnewRideView in it and have it pass itself to the method.
It's hard to explain but I'll show you an example:
cancelAddingNewRide class:
- (IBACtion)home:(id)sender {
if (self.delegate respondsToSelctor:#selector(dismiss:)]) {
[self.delegate dismiss:self];
}
}
and then in the showAddNewRideView class
-(void) dismiss:(cancelAddingNewRide_class *) controller {
[self dismissModalViewControllerAnimated:Yes];
}
Hope that makes sense and soz for typos
Edit: oh and make the controller's delegate self
controller.delegate = self;
Actually thinking about it more there is a bit more to this. You have to define the called viewController as a Delegate. Have a look at Stanford universities iPhone lectures, lecture 11 deals with this and is available from iTunesU.