NSInvalidArgumentException for implementing UIWebView - objective-c

I am writing an app for iPad. I have several views. On navigation bar I have 2 buttons for shopping cart and youtube. pressing them takes to the browser in the app itself. I have made another class for browser and added an outlet for UIWebView. In browser class viewDidLoad method I wrote the following lines.
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.hidesBackButton = YES;
self.title = #"Browser";
[webView loadRequest:[NSURL URLWithString:#"http://cfsmail.com"]];
}
The build is successful and app runs. But when I press any of those buttons it terminates with following error.
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSURL URL]: unrecognized selector sent to instance 0x4b39600'
Please guide
Regards
Prateek

What you are doing wrong is that loadRequest requires a NSURLRequest, not NSURL. Try:
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://cfsmail.com"]]];

Related

Reload Data throwing unrecognized selector sent to instance

I seem to be experiencing a small error when dismissing a view and navigating back to a ViewController (with a UITableView)
This is the code that loads the data into the tableView
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[getData getSavedTanks:^(NSArray *results) {
self.array = results;
[self.tankList reloadData];
NSLog(#"%#", results);
}];
}
The followup view in the stack is properly called, but when the view is dismissed, it seems as though the tableView has trouble reloading the data, and is throwing this error:
2014-04-28 21:15:57.698 ReefTrack[10205:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[PFObject reloadData]: unrecognized selector sent to instance 0x10be93210'
Not really sure how to handle this. I'm having trouble understanding why reloadData is throwing an error. I checked to see if there are any errant Segues pointing towards reload data but there doesn't appear to be. Anyone have any thoughts on this?
UPDATE:
This was solved by placing the entire function in viewDidLoad.

Changing views works in viewDidLoad but not on a button click IBAction

I want to open up a new view with the identifier AddSourceViewController when a button is clicked. I'm using the following code to do so:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard_iPhone" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:#"AddSourceViewController"];
[vc setModalPresentationStyle:UIModalPresentationFullScreen];
[self presentModalViewController:vc animated:YES];
When used in viewDidLoad on an initial view, this code works perfectly and opens up the additional view. However, I have added an IBAction to a button on the initial view and when I add the above code to attempt to open the new view on button click, I just get a Thread 1: breakpoint 5.1 6.1. How can I get this to work on the button action?
EDIT: Better error information below.
2012-11-23 16:33:40.399 Marketr[23454:c07] -[SecondViewController addSourceButton:]: unrecognized selector sent to instance 0x6e2f5c0
2012-11-23 16:33:40.400 Marketr[23454:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[SecondViewController addSourceButton:]: unrecognized selector sent to instance 0x6e2f5c0'
Do you have a breakpoint set for your action method? Look on the left side next to the code of this method, to see if there is a blue arrow pointing towards the code.

Can I have a block of code run only if user is on iPhone vs iPad?

I have a master-detail app that is working great for the iPad. However, the iPhone version doesn't work because a variable that is being sent to the DetailViewController in the iPad version doesn't send to the iPhone DetailViewController. I can fix this with a single line of code in MasterViewController implementation:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
self.detailViewController=segue.destinationViewController;
}
Unfortunately, when I implement that code, the iPad version stops working. I get an exception when I go from another view controller (HomeViewController) back to DetailViewController. That error log is:
2012-07-14 14:29:12.924 46 Tracker[2772:11603] -[HomeViewController setDetailItem:]: unrecognized selector sent to instance 0x7cad4f0
2012-07-14 14:29:12.925 46 Tracker[2772:11603] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[HomeViewController setDetailItem:]: unrecognized selector sent to instance 0x7cad4f0'
*** First throw call stack:
(0x148a022 0x201acd6 0x148bcbd 0x13f0ed0 0x13f0cb2 0x2cb0 0x2d75c5 0x2d77fa 0xb6c85d 0x145e936 0x145e3d7 0x13c1790 0x13c0d84 0x13c0c9b 0x16a07d8 0x16a088a 0x246626 0x1fdd 0x1f45)
terminate called throwing an exception(lldb)
So, is there any way I can run that first block of code only when the user is on the iPhone? Or, can I fix the code to make it work properly on both devices?
Here is a link to my iPad storyboard to (hopefully) make it more clear. I have a problem when I click on a table cell AFTER going from HomeViewController back to DetailViewController: http://www.grapekeeper.com/storyboards.png
Perhaps the following?
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
// perform iPad logic
} else {
// perform iPhone logic
}

Use property leftItemsSupplementBackButton of UINavigationItem Class

In my app I want to show a button item together the back button in the navigation bar. I read the doc of the UINavigationItem class and I found the property leftItemsSupplementBackButton that seems to be just for me. Then I used this line of code:
- (void)viewDidLoad{
[super viewDidLoad];
[self.navigationItem setLeftItemsSupplementBackButton:YES];
}
But when I run the app I get this error:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UINavigationItem setLeftItemsSupplementBackButton:]: unrecognized selector sent to instance 0x10faefb0'
and the 0x10faefb0 instance is:
_navigationItem UINavigationItem * 0x10faefb0
From the error seems that self.navigationItem doesn't have this property as is said in the apple class reference. Where i'm wrong?
That's for iOS 5 only. Are you running on iOS 4?

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIPopoverController modalTransitionStyle]:

i used the following code to display my image picker controll.
IPopoverController *popoverController = [[[UIPopoverController alloc] initWithContentViewController:myImagePicker] retain];
[self presentModalViewController:popoverController animated:YES];
but there is a error that shows
working with image view[14335:207] *
Terminating app due to uncaught
exception
'NSInvalidArgumentException', reason:
'-[UIPopoverController
modalTransitionStyle]: unrecognized
selector sent to instance 0x6415950'.
can any one help me please.
You need to use this...
[popoverController presentPopoverFromBarButtonItem:sender
permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
Or one of the other present methods, check the Apple docs.
The short answer is that you cannot use UIPopoverController to present it as a modal one. Please try using UIViewController instead.
You probably will need to subclass it and either load it from some nib or create its view content manually in loadView method.