I Am creating an iPhone application which displays an UITableView at the start with some text in the cells. When a user taps a cell it should transition to another view. When I run the application in the iPhone Simulator and click on a cell I get the following error:
2009-09-23 12:20:03.554 ZDFMobiel[751:20b] *** Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: '*** -[RootViewController eigenRisicoView]:
unrecognized selector sent to instance 0xd1d1a0'
2009-09-23 12:20:03.555 ZDFMobiel[751:20b] Stack: (
Here is the function (In RootViewController.m) where the error occurred. It happens at the
if(self.eigenRisicoView == nil) {
line or the at the other if statements, depending on which cell you click.
// Override to support row selection in the table view.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
ZDFMobielAppDelegate *appDelegate = (ZDFMobielAppDelegate *)[[UIApplication sharedApplication] delegate];
NSString *content = (NSString *)[appDelegate.menuItems objectAtIndex:indexPath.row];
switch (indexPath.row) {
case 0:
if(self.eigenRisicoView == nil) {
EigenRisicoViewController *viewController = [[EigenRisicoViewController alloc] initWithNibName:#"EigenRisicoViewController" bundle:[NSBundle mainBundle]];
self.eigenRisicoView = viewController;
[viewController release];
}
[self.navigationController pushViewController:self.eigenRisicoView animated:YES];
self.eigenRisicoView.title = content;
break;
case 1:
if(self.declaratieStatusView == nil) {
DeclaratieStatusViewController *viewController = [[DeclaratieStatusViewController alloc] initWithNibName:#"DeclaratieStatusViewController" bundle:[NSBundle mainBundle]];
self.declaratieStatusView = viewController;
[viewController release];
}
[self.navigationController pushViewController:self.declaratieStatusView animated:YES];
self.declaratieStatusView.title = content;
break;
case 2:
if(self.vergoedingenView == nil) {
VergoedingenViewController *viewController = [[VergoedingenViewController alloc] initWithNibName:#"VergoedingenViewController" bundle:[NSBundle mainBundle]];
self.vergoedingenView = viewController;
[viewController release];
}
[self.navigationController pushViewController:self.vergoedingenView animated:YES];
self.vergoedingenView.title = content;
break;
case 3:
if(self.zoekenZorgInstView == nil) {
ZoekenZorgInstViewController *viewController = [[ZoekenZorgInstViewController alloc] initWithNibName:#"ZoekenZorgInstViewController" bundle:[NSBundle mainBundle]];
self.zoekenZorgInstView = viewController;
[viewController release];
}
[self.navigationController pushViewController:self.zoekenZorgInstView animated:YES];
self.zoekenZorgInstView.title = content;
break;
default:
break;
}
// Navigation logic may go here -- for example, create and push another view controller.
// AnotherViewController *anotherViewController = [[AnotherViewController alloc] initWithNibName:#"AnotherView" bundle:nil];
// [self.navigationController pushViewController:anotherViewController animated:YES];
// [anotherViewController release];
}
This is my RootControllerView.h file
#import "EigenRisicoViewController.h";
#import "DeclaratieStatusViewController.h";
#import "VergoedingenViewController.h";
#import "ZoekenZorgInstViewController.h";
#import "ZDFMobielAppDelegate.h";
#interface RootViewController : UITableViewController {
EigenRisicoViewController *eigenRisicoView;
DeclaratieStatusViewController *declaratieStatusView;
VergoedingenViewController *vergoedingenView;
ZoekenZorgInstViewController *zoekenZorgInstView;
}
#property(nonatomic,retain) EigenRisicoViewController *eigenRisicoView;
#property(nonatomic,retain) DeclaratieStatusViewController *declaratieStatusView;
#property(nonatomic,retain) VergoedingenViewController *vergoedingenView;
#property(nonatomic,retain) ZoekenZorgInstViewController *zoekenZorgInstView;
#end
I Am new to iPhone development, Objective C and XCode so I don't understand what the error means..
Does anyone know what I am doing wrong?
I'd need to see the whole implementation, but it sounds like you didnt #synthesize eigenRisicoView;
Related
Each row clicked will lead you to another view controller
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
if( indexPath.row == 0 ){
titleController = [[TitleFundraiserController alloc] initWithNibName:#"TitleFundraiserController" bundle:nil];
[self.navigationController presentViewController:titleController animated:YES completion:nil];
}
if( indexPath.row == 1 ) {
recipientController = [[RecipientController alloc] initWithNibName:#"RecipientController" bundle:nil];
[self.navigationController presentViewController:recipientController animated:YES completion:nil];
}
if( indexPath.row == 2 ) {
fundController = [[FundingController alloc] initWithNibName:#"FundingController" bundle:nil];
[self.navigationController presentViewController:recipientController animated:YES completion:nil];
}
if( indexPath.row == 3 ) {
locationController = [[LocationController alloc] initWithNibName:#"LocationController" bundle:nil];
[self.navigationController presentViewController:locationController animated:YES completion:nil];
}
}
However, sometimes I am getting this error from the console and my program is crashing
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason:
'Application tried to present a nil modal view controller on target <UINavigationController: 0x7c7a340>.'
I dont know why it is saying so .
Please help if you have experienced this issue before.
Thanks
You are presenting recipientController in your if (indexPath.row == 2) statement when you should be presentingfundController
Here is the corrected code:
if( indexPath.row == 2 ) {
fundController = [[FundingController alloc] initWithNibName:#"FundingController" bundle:nil];
[self.navigationController presentViewController:fundController animated:YES completion:nil];
}
You are getting that error, because recipientController would be nil when presenting here
The only thing I see wrong with your code is that after presentViewController, you need to release the variable as well:
if ( indexPath.row == 0 ) {
titleController = [[TitleFundraiserController alloc] initWithNibName:#"TitleFundraiserController" bundle:nil];
[self.navigationController presentViewController:titleController animated:YES completion:nil];
[titleController release];
}
I don't see any reason for the error you are getting being random, isn't it always in the same row?. What is happening is the ViewController is not being loaded from the nib and therefore returning nil.
Trying to launch a viewcontroller in connectiondidfinish delegate method of NSUrlConection
//Sprequest.m inherited from nsobject
- (void)connectionDidFinishLoading:(NSURLConnection *)conn {
NSLog(#"connectionDidFinishLoading ");
if(nStatus == 401)
{
NSLog(#"called maincontroller to launch dvrview");
MainController *mainview =[[MainController alloc] init];
[mainview reponseFromServer];
}
}
//maincontroller.m from viewcontroller
-(void)reponseFromServer
{
NSLog(#"response from server - main controller ");
dvrView *dvrObj = [[dvrView alloc]initWithNibName:#"dvrView" bundle:nil];
[self.navigationController pushViewController:dvrObj animated:YES];
}
this dvr view doesnt get loaded
Sprequest.m is inherited from NSObject , its not a viewController subclass so you cant use
[self.navigationController pushViewController:dvrObj animated:YES];
inside Sprequest.m
You can get the navigationController object from the appdelegate like this
((AppDelegate *)[UIApplication sharedApplication].delegate).navigationController
then use
[((AppDelegate *)[UIApplication sharedApplication].delegate).navigationController pushViewController:dvrObj animated:YES];
does EKEventEditViewController not support being pushed to a NavController? See code & error attached.
I can present the EKEventEditViewController modally fine, BUT when I try to push via the nav controller I get the following error:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Pushing a navigation controller is not supported'
Code is:
EKEventEditViewController *addController = [[[EKEventEditViewController alloc] initWithNibName:nil bundle:nil] autorelease];
addController.eventStore = self.eventStore;
addController.editViewDelegate = self;
[self.navigationController pushViewController:addController animated:TRUE]; // ERROR HERE
EKEventEditViewController is subclass of UINavigationController, so it can't be pushed to another UINavigationController.
EKEventEditViewController should be presented modally.
EKEventEditViewController Class Ref
In case you're looking for some code to jumpstart an iPad-with-popover implementation:
EKEventStore *eventStore [[EKEventStore alloc] init];
EKEventEditViewController *eventController = [[EKEventEditViewController alloc] init];
eventController.editViewDelegate = self;
eventController.eventStore = eventStore;
EKEvent *event = [EKEvent eventWithEventStore: eventStore];
event.title = #"New Event";
event.startDate = [[NSDate alloc] init];
event.endDate = [[NSDate alloc] initWithTimeInterval: 60 * 60 sinceDate: event.startDate];
eventController.event = event;
/* You can add EKEventEditViewController directly to the popover -- this had me baffled for _hours_ */
popover = [[UIPopoverController alloc] initWithContentViewController: eventController];
You will also want to include this delegate method to do whatever you need to when the user completes or cancels event editing:
- (void) eventEditViewController: (EKEventEditViewController *)controller didCompleteWithAction: (EKEventEditViewAction)action
{
EKEvent *thisEvent = controller.event;
switch (action) {
case EKEventEditViewActionCanceled:
NSLog(#"Canceled action");
break;
case EKEventEditViewActionSaved:
NSLog(#"Saved action: %#", thisEvent.startDate);
break;
case EKEventEditViewActionDeleted:
NSLog(#"Deleted action");
break;
default:
break;
}
[popover dismissPopoverAnimated: YES];
}
Enjoy!
Mark
For future readers:
EKEventEditViewController is a UINavigationController so you can just say:
EKEventEditViewController *controller = [[EKEventEditViewController alloc] init];
// Set your properties here
[self.navigationController pushViewController:controller.viewControllers[0] animated:YES];
This works for me, but I don't know if you can do this for Apple.
something isn't working right and i can't work out why this isn't working to load my other nib, this currently works
#pragma mark - Flipside View
- (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller
{
[self dismissModalViewControllerAnimated:YES];
}
- (IBAction)showInfo:(id)sender
{
FlipsideViewController *controller = [[FlipsideViewController alloc] initWithNibName:#"FlipsideViewController" bundle:nil];
controller.delegate = self;
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:controller animated:YES];
}
whilst i've done the exact same thing here on the same MainViewController.m and had no success whilst doing it
#pragma mark - News View
- (void)newsViewControllerDidFinish:(NewsViewController *)controller
{
[self dismissModalViewControllerAnimated:YES];
}
- (IBAction)showNews:(id)sender
{
NewsViewController *controller = [[NewsViewController alloc] initWithNibName:#"NewsViewController" bundle:nil];
controller.delegate = self;
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:controller animated:YES];
}
so i think there is something wrong with my header file which looks like this
#import "FlipsideViewController.h"
#import "NewsViewController.h"
#interface MainViewController : UIViewController <FlipsideViewControllerDelegate, NewsViewControllerDelegate>
- (IBAction)showInfo:(id)sender;
- (IBAction)showNews:(id)sender;
#end
I can't work out why it's not working, any help would be appreciated.
Error from output:
This GDB was configured as "x86_64-apple-darwin".Attaching to
process 2147.
2011-07-08 12:24:09.845 Danny[2147:ef03] -[NewsViewController
setDelegate:]: unrecognized selector
sent to instance 0x68a62b0
2011-07-08 12:24:09.847 Danny[2147:ef03] * Terminating app
due to uncaught exception
'NSInvalidArgumentException', reason:
'-[NewsViewController setDelegate:]:
unrecognized selector sent to instance
0x68a62b0'
* First throw call stack:
(0xf8a600 0x112252e 0xf8d550 0xeeb4cf 0xeeb292 0x2a36 0xf8bd78
0x18cc5 0x18c5a 0xbdbd4 0xbe09d
0xbd368 0x3e004 0x3e22d 0x24990
0x181a7 0x1369886 0xf59d11 0xebbc9b
0xeba4b1 0xeb993c 0xeb9868 0x1367fef
0x13680b4 0x160c4 0x2009 0x1f75)
terminate called throwing an exceptionsharedlibrary
apply-load-rules all
Current language: auto; currently objective-c
(gdb)
What is the delegate method for the view controller? Check if the declaration of the delegate method is the same. Make sure you have set the delegates properly
Try this:
- (IBAction)showNews:(id)sender
{
NewsViewController *controller = [[NewsViewController alloc] initWithNibName:#"NewsViewController" bundle:nil];
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:controller animated:YES];
}
And in the News View, instead of writing
[self.delegate newsViewControllerDidFinish:self];
you should write:
[self dismissModalViewControllerAnimated:YES];
That should solve your problem. I don't see much point in writing extra delegates, they don't usually give you any advantages (in scenarios like this one), when you can just have a view controller dismiss itself.
I have two ViewControllers: The RedButtonViewController and the TweetViewController. The RedButtonViewController generates random numbers in Textlabels and I want to use the number or the label with the TweetViewController. How can I make this?
Thanks for your help!
My TweetViewController will be opened with this code in the RedButtonViewController:
- (IBAction)TweetViewController:(id)sender {
TweetViewController *Tweet = [[TweetViewController alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:Tweet animated:YES];
}
Here is an exemple of how I generate the random number:
- (IBAction)pushRedButton:(UIButton *)sender {
int ZahlDerToten;
ZahlDerToten = arc4random() % 1000000;
outputLabel.text = [NSString stringWithFormat:#"You killed %d people.", ZahlDerToten];
Create a property on the TweetViewController and set it before presenting it:
- (IBAction)TweetViewController:(id)sender {
// Note: don't put leading capitals on a local variable
TweetViewController *tweet = [[TweetViewController alloc] initWithNibName:nil bundle:nil];
tweet.randomNumber = [self generateRandomNumber];
[self presentModalViewController:tweet animated:YES];
// Note: You were leaking the view controller
[tweet release];
}
Another solution (and how I usually do this kind of thing) is to create a new initializer called -initWithNumber: (probably something a little more descriptive than "number") and call it like this:
- (IBAction)TweetViewController:(id)sender {
TweetViewController *tweet = [[TweetViewController alloc] initWithNumber:[self generateRandomNumber]];
[self presentModalViewController:tweet animated:YES];
[tweet release];
}
-initWithNumber would then look something like:
- (TweetViewController *)initWithNumber:(NSInteger)number {
self = [super initWithNibName:nil bundle:nil];
if (self != nil) {
self.number = number;
}
return self;
}