I am making a blog reader app. Everything works fine until I try to access the detailView from a cell. I receive this error,
[UINavigationController setPFeedURL:]: unrecognised selector sent to instance 0x7f96d5802800
below code is in the PRTableViewController.m
#import "PRTableViewController.h"
#import "PRFeedPost.h"
#import "PRDetailViewController.h"
This is where the code is where the crash happens
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if ([segue.identifier isEqualToString:#"showDetail"]){
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
PRFeedPost *feed_Post = [self.polisenFeed objectAtIndex:indexPath.row];
[segue.destinationViewController setPFeedURL:feed_Post.url];
}
}
This is to help you understand what I am trying to setPFeedURL to. Also in PRViewTableController.m
self.polisenFeed = [NSMutableArray array];
NSArray *polisenFeedArray = [dataDictionary objectForKey:#"posts"];
for (NSDictionary *postDictionary in polisenFeedArray) {
PRFeedPost *fp = [PRFeedPost feedWithTitle:[postDictionary objectForKey:#"title"]];
fp.author = [postDictionary objectForKey:#"author"];
fp.thumbnail = [postDictionary objectForKey:#"thumbnail"];
fp.date = [postDictionary objectForKey:#"date"];
fp.url = [NSURL URLWithString:[postDictionary objectForKey:#"url" ]];
[self.polisenFeed addObject:fp];
}
Now the PRDetailViewController.h,
This is where the property is I am trying to set is,
#property (strong, nonatomic) NSURL *pFeedURL;
#property (strong, nonatomic) id detailItem;
#property (strong, nonatomic) IBOutlet UIWebView *webView;
Here is the code in PRDetailViewController.m,
- (void)viewDidLoad {
[super viewDidLoad];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:self.pFeedURL];
[self.webView loadRequest:urlRequest];
I cannot seem to figure out why this is crashing. I know it has to do with this line ,
[segue.destinationViewController setPFeedURL:feed_Post.url];
(at leaset I think it is that line. I can't figure out why I cannot set it.
Thanks for your help guys!
Change This
PRDetailViewController *objPRDetailViewController = (PRDetailViewController *)[segue.destinationViewController topViewController];
objPRDetailViewController.pFeedURL=feed_Post.url;
And Also put bellow code in viewDidAppear
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:self.pFeedURL];
[self.webView loadRequest:urlRequest];
try this
[[((id)segue.destinationViewController) topViewController] setPFeedURL:feed_Post.url];
let me know if it works
Related
Here is my button function where I pass the data.
The problem is Area and Country details are passed to the next ViewController but latitude and longitude return null.
In ViewController.m :
- (IBAction)forecast:(UIButton *)sender
{
ForecastViewController *sendDetails = [[ForecastViewController alloc] init];
NSArray *seperate = [full componentsSeparatedByString:#", "];
Area = seperate[0];
Country = seperate[1];
sendDetails.Area = Area;
sendDetails.Country = Country;
NSLog(#"%#%#",self.longitude,self.latitude);
NSString *lt = self.latitude;
NSString *ln = self.longitude;
sendDetails.longitude = lt;
sendDetails.latitude = ln;
}
In ForecastViewController.h
//
// ForecastViewController.h
// Weather App
//
// Created by Mac-Mini-2 on 10/02/16.
// Copyright © 2016 Mac-Mini-2. All rights reserved.
//
#import <UIKit/UIKit.h>
#import <CoreData/CoreData.h>
#import <Reachability.h>
#interface ForecastViewController : UIViewController <UITableViewDataSource,UITableViewDelegate>
#property (weak, nonatomic) IBOutlet UILabel *place;
#property (weak, nonatomic) IBOutlet UITableView *table;
#property (weak, nonatomic) IBOutlet UIActivityIndicatorView *activityIndicator;
#property NSString *Area;
#property NSString *Country;
#property NSString *latitude;
#property NSString *longitude;
#end
In ForecastViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.table.delegate = self;
self.table.dataSource = self;
self.place.text = [NSString stringWithFormat:#"%#, %#",self.Area,self.Country];
locationName = [NSString stringWithFormat:#"%#, %#",self.Area,self.Country];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
metric = [defaults boolForKey:#"metric"];
Reachability *reach = [Reachability reachabilityWithHostName:#"www.google.com"];
NSInteger x = [reach currentReachabilityStatus];
if (x > 0)
{
reachable = YES;
NSLog(#"%#, %#",self.latitude,self.longitude);
[self getForecast:self.latitude longitudes:self.longitude];
}
else
{
reachable = NO;
[self getData];
errorMsg = #"Because of unavailability of Network Realtime information wont be available.";
[self performSelectorOnMainThread:#selector(displayAlert) withObject:NULL waitUntilDone:YES];
}
[reach startNotifier];
}
Please let me know where I could have gone wrong here.
I checked by logging the data onto console. The area and country is printed but longitude and latitude give null values.
if you are doing a push to ForecastViewController, maybe implementing prepareForSegue:sender: is your best option.
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"viewForecast"]){
NSArray *seperate = [full componentsSeparatedByString:#", "];
Area = seperate[0];
Country = seperate[1];
[(ForecastViewController *) [segue destinationViewController] setArea:area];
[(ForecastViewController *) [segue destinationViewController] setCountry:country];
...
...
}
}
Could I the that latitude and longitude are stored as numbers in the first controller? Are you sure that 'sendDetails.latitude' and 'longitude' are set correctly in 'ViewController'?
I think you need to edit two point firstly in ForecastViewController.h set
#property (Strong, nonatomic) NSString *Area;
#property (Strong, nonatomic) NSString *Country;
#property (Strong, nonatomic) NSString *latitude;
#property (Strong, nonatomic) NSString *longitude;
and #synthsize it in ForecastViewController.m.
secondly:-
- (IBAction)forecast:(UIButton *)sender
{
ForecastViewController *sendDetails = [self.storyboard instantiateViewControllerWithIdentifier:#"your ForecastViewController name in storyboard"];
NSArray *seperate = [full componentsSeparatedByString:#", "];
Area = seperate[0];
Country = seperate[1];
sendDetails.Area = Area;
sendDetails.Country = Country;
NSLog(#"%#%#",self.longitude,self.latitude);
NSString *lt = self.latitude;
NSString *ln = self.longitude;
sendDetails.longitude = lt;
sendDetails.latitude = ln;
[self.navigationController pushViewController:sendDetails animated:YES];
}
I made a button in storyboard and associated it with an IBAction in my header file. How can I set the title of this button to the variable I made displayPhone and have it call that number as well?
.h
#import <UIKit/UIKit.h>
#import <Parse/Parse.h>
#interface IBThirdViewController : UIViewController
#property (nonatomic, strong) PFRelation *agentRelation;
#property (nonatomic, strong) NSArray *agent;
#property (weak, nonatomic) IBOutlet UILabel *agentName;
#property (strong, nonatomic) IBOutlet UILabel *agentPhone;
#property (strong, nonatomic) IBOutlet UILabel *agentEmail;
#property (strong, nonatomic) IBOutlet UIImageView *agentImage;
- (IBAction)phoneButton:(id)sender;
#end
.m
#import "IBThirdViewController.h"
#import "IBAgentsTableViewController.h"
#interface IBThirdViewController ()
#end
#implementation IBThirdViewController
- (void)viewDidLoad {
[super viewDidLoad];
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
//Find the Agent and show it
self.agentRelation = [[PFUser currentUser] objectForKey:#"agentRelation"];
PFQuery *query = [self.agentRelation query];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
// success
self.agent = objects;
// Do something with the found objects
for (PFObject *object in objects) {
NSLog(#"name: %#", [object objectForKey:#"name"]);
NSLog(#"email: %#", [object objectForKey:#"email"]);
NSString *displayEmail = [object objectForKey:#"email"];
NSString *displayName = [object objectForKey:#"name"];
NSString *displayPhone = [object objectForKey:#"phone"];
PFFile *thumbnail = [object objectForKey:#"profilePic"];
NSURL *imageFileURL = [[NSURL alloc] initWithString:thumbnail.url];
NSData *imageData = [NSData dataWithContentsOfURL:imageFileURL];
self.agentEmail.text = displayEmail;
self.agentName.text = displayName;
self.agentPhone.text = displayPhone;
self.agentImage.image = [UIImage imageWithData:imageData];
}
} else {
// Log details of the failure
NSLog(#"Error: %# %#", error, [error userInfo]);
}
}];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"showEditAgent"]) {
IBAgentsTableViewController *viewController = (IBAgentsTableViewController *)segue.destinationViewController;
viewController.agents = [NSMutableArray arrayWithArray:self.agent];
}
}
- (IBAction)phoneButton:(id)sender {
}
#end
First of all you need connect button from xib with IBOutlet object:
#property (nonatomic, weak) IBOutlet UIButton *displayPhone;
Then set it's title in -(void)viewDidAppear:(BOOL)animated after loading data:
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
//...
// Load data here
//...
[self.displayPhone setTitle:displayPhone forState:UIControlStateNormal];
}
Finally implement IBAction method for button:
- (IBAction)phoneButton:(id)sender {
NSString *phone = [sender titleForState:UIControlStateNormal];
// Remove all chars except of digits
static NSString *const kDigitsString = #"0123456789";
phone = [[phone componentsSeparatedByCharactersInSet:[[NSCharacterSet characterSetWithCharactersInString:kDigitsString] invertedSet]] componentsJoinedByString:#""];
// Initiate call
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:#"tel:%#", phone]]];
}
It looks like you haven't connected the button to an outlet but only to an action.
First you need to connect it to an outlet (like you've done with the labels).
Then use...
[self.button setTitle:#"blah" forState:UIViewControlStateNormal];
Something like that anyway. I'm currently on my iPhone so I don't have auto complete.
If you want to change the title inside the IBAction method do:
[sender setTitle:#"My title" forState:UIControlStateNormal];
If you want to change in any other place you need a #property of uibutton, something like this
#property (strong, nonatomic) IBOutlet UIButton *phoneButtonProperty;
and connect it to your button and then
[phoneButtonProperty setTitle:#"My title" forState:UIControlStateNormal];
I am having a hard time figuring out how to pass a NSString to a NSObject class.
I have a .h and .m file which is a NSObject and I need to pass a string from a UIViewController.
This is what I tried when pushing the view:
NSString *urlString = #"TextHere";
WXClient *svc = [[WXClient alloc]init];
svc.urlOne = urlString
And then, I am retrieving it this way:
#interface WXClient : NSObject {
NSString *urlOne;
}
#property (strong, nonatomic) NSString *urlOne;
and of course, then on the .m :
#synthesize urlOne;
Then to use the NSString:
NSString *urlString = [NSString stringWithFormat:urlOne];
NSURL *url = [NSURL URLWithString:urlString];
//blah blah blah blah... :D
}];
But for some reason it is returning null. I am able to use this method from viewController to viewController but to NSObject is not working :(
Any ideas?
Thanks!
Try this
WXClient *svc = [[WXClient alloc]init];
NSString *urlString = #"TextHere";
svc.urlOne = urlString;
Sorry didn't read question properly
If you are pushing/presenting view controller throug segue and you want to send some data to destination view contrller. Like you want to set some property, you need to implement this method. prepareForSegue:sender:.
In it you you can get destination viewController and set whatever property you want to.
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"weatherWXID"]) {
WeatherViewController *vc = [segue destinationViewController];
NSString *urlString = #"TextHere";
WXClient *svc = [WXCLient new];
svc.urlOne = urlString
vc.wxclient = svc;
}
}
I re-re edit my question : it's for about two weeks that i set up my WebView in my application, everything was going well working together. Yesterday i wanted to just see if the webView is still working even if i didn't change any of the class's code, and boom SIGABRT. So today i decided to change my UIWebView to a programmatically coded WebView. The problem is xcode is still asking for a IBOutlet that i don't use :O. If someone with advanced objective c skills could help me i'm going crazy.
Log message : `
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "MyWebView" nib but the view outlet was not set.'`
here is my code :
- (void)showWebView;
{
//here i call my webview in my RootViewController
ViewController *WebViewVC = [[ViewController alloc] init];
[[self navigationController] pushViewController:WebViewVC animated:YES];
[WebViewVC pushIt];
}
//here is my WebViewController.h
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#interface ViewController : UIViewController <UIWebViewDelegate>
{
//IBOutlet UIWebView *myWebView;
UIWebView *newWeb;
}
//#property (nonatomic, retain) IBOutlet UIWebView *myWebView;
-(void)XButton;
-(void)pushIt;
#end
//here is my WebViewController.m
-(void)pushIt;
{
self.navigationItem.hidesBackButton = YES;
self.navigationItem.leftBarButtonItem = nil;
self.title = #"*****";
self.title = #"Endosize";
newWeb = [[UIWebView alloc] initWithFrame:self.view.frame];
[self.view addSubview:newWeb];
[self XButton];
[self WebViewBrowserBackButton];
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
NSString *defaults = [prefs stringForKey:#"myKey"];
NSString *defaults2 = [prefs stringForKey:#"mySecondKey"];
NSString *username = defaults;
NSString *password = defaults2;
NSURL* url = [NSURL URLWithString:#"**************"];
NSString* body = [NSString stringWithFormat:#"************", username, password];
NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:30];
request.HTTPMethod = #"POST";
request.HTTPBody = [body dataUsingEncoding:NSStringEncodingConversionAllowLossy];
[newWeb loadRequest:request];
}
The .xib file of your parent view controller has probably a UIWebView connected. Remove that connection and try running the app again.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
This is probably is pretty easy, but I'm stuck with it today.
The idea is that in my browser, I've create uiwebview and I want to implimate address bar in popover with it own class.
I can get the url from UItextfield from popover class to webview class, but when I get it uiwebview get lazy and it doesn't load it.
When I check it, debuger says that webview is null.
This is ViewController.h
#import <UIKit/UIKit.h>
#import "AdressBar.h"
#import "mypopoverController.h"
#interface ViewController : UIViewController<AddressbarDelegate>
{
UIWebView* mWebView;
mypopoverController *popoverController;
}
#property (nonatomic, retain) IBOutlet UIWebView* webPage;
#end
This is ViewController.m:
#import "mypopoverController.h"
#import "MyOwnPopover.h"
#import "ViewController.h"
#import "AdressBar.h"
#interface ViewController ()
#end
#implementation ViewController
#synthesize webPage = mWebView;
- (void)viewDidLoad
{
[super viewDidLoad];
addressBar = [[AdressBar alloc] init];
addressBar.delegate = self;
[edittext addTarget:self action:#selector(showPopoverAdressBar:forEvent:) forControlEvents:UIControlEventTouchUpInside];
NSURL *url = [NSURL URLWithString:#"http://www.google.lv"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[mWebView setScalesPageToFit:YES];
[mWebView setDelegate:self];
[mWebView loadRequest:request];
}
-(void)loadReceivedAddress:(NSURLRequest *)url{
NSLog(#"url= %#", url);//there url always is not null and mWebView should load it
if(mWebView != nil){
[mWebView loadRequest:url];
}else{
NSLog(#"mWebView is null");//...but there it say's that it's null
}}
-(void)showPopoverAdressBar:(id)sender forEvent:(UIEvent*)event
{
AdressBar *popoverControllesr = [[AdressBar alloc]init];
popoverControllesr.view.frame = CGRectMake(0,0, 600, 45);
popoverControllesr.view.backgroundColor = [UIColor whiteColor];
popoverController = [[mypopoverController alloc] initWithContentViewController:popoverControllesr];
popoverController.cornerRadius = 20;
if(_titles!=NULL){
popoverController.titleText = _titles;}else{
popoverController.titleText = #"Loading...";
}
popoverControllesr.address.text = absoluteString;
popoverController.popoverBaseColor = [UIColor orangeColor];
popoverController.popoverGradient= YES;
popoverController.arrowPosition = TSPopoverArrowPositionHorizontal;
[popoverController showPopoverWithTouch:event];
}
#end
This is AdressBar.h
#import <UIKit/UIKit.h>
#protocol AddressbarDelegate <NSObject>
#required
-(void)loadSomethingFromAddressBar:(NSURLRequest*)request;
#end
#interface AdressBar : UIViewController{
IBOutlet UIButton *cancel;
}
#property (nonatomic, retain) IBOutlet UITextField *address;
#property (nonatomic, retain) NSURLRequest *request;
#property(nonatomic, weak) id <AddressbarDelegate> delegate;
#end
This is AdressBar.m:
#import "AdressBar.h"
#import "ViewController.h"
#interface AdressBar ()
#end
#implementation AdressBar
#synthesize delegate = delegate;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
[_address setDelegate:self];
_address.clearButtonMode =
UITextFieldViewModeWhileEditing;
_address.keyboardType = UIKeyboardTypeURL;
[_address addTarget:self
action:#selector(loadAddresss)
forControlEvents:UIControlEventEditingDidEndOnExit];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)loadAddresss {
NSString* urlString = _address.text;
NSURL* url = [NSURL URLWithString:urlString];
if(!url.scheme)
{
NSString* modifiedURLString = [NSString stringWithFormat:#"http://%#", urlString];
url = [NSURL URLWithString:modifiedURLString];
}
NSURLRequest *request = [NSURLRequest requestWithURL:url];
NSLog(#"request= %#", request);
NSLog(#"text= %#", urlString);
if (request!=nil) {
if(delegate!=nil)
{NSLog(#"delegate not nil");
[delegate loadSomethingFromAddressBar:request];
}else{
NSLog(#"delegate is nil");//There delegate always is nil
}
}
}
#end
Make sure that your web view Outlet & Delegate is correctly conncted.
There no space between URL Address because I also face the same issue. Try to open that url in web-Browser.
If this is your view hierarchy
---- In ViewController
---- Showing AddressBar View in POPOver
---- Remove POPover and display ViewController's web view
I suggest create a custom delegate method in AddressBar and when you remove the popOver trigger the delegate method. Implement the delegate in your ViewContrller and call loadSomethingFromAddressBar in that implemented delegate method
Note : make sure you have connected you webpage IBOutlet to your nib file.
// In Adressbar.h
#protocol AddressbarDelegate <NSObject>
#required
-(void)loadYourWebViewNow:(NSURLRequest*)request;
#end
#interface Addressbar : UIViewController
{
}
#property(nonatomic, weak) id <AddressbarDelegate>
// In Adressbar.m
- (void)loadAddresss {
NSString* urlString = _address.text; //geting text from UItextField
NSURL* url = [NSURL URLWithString:urlString];
if(!url.scheme)
{
NSString* modifiedURLString = [NSString stringWithFormat:#"http://%#", urlString];
url = [NSURL URLWithString:modifiedURLString];
}
NSURLRequest *request = [NSURLRequest requestWithURL:url];
if (request!=nil) {
NSLog(#"request is good");
if(_delegate!=nil)
{
[_delegate loadYourWebViewNow:request];
}
}
// In your ViewController.h
#interface ViewController : UIViewController<AddressbarDelegate>
{
//AdressBar *addressBar;
}
// In your ViewController.m implement the delegate method and set the delegate
#implementation ViewController
-(void)viewDidLoad
{
Remove these two below lines on viewDidLoad
//addressBar = [[Adressbar alloc] init];
//addressbar.delegate = self;
}
-(void)loadYourWebViewNow:(NSURLRequest*)request
{
[self loadSomethingFromAddressBar:request];
}
-(void)showPopoverAdressBar:(id)sender forEvent:(UIEvent*)event
{
AdressBar *popoverControllesr = [[AdressBar alloc]init];
popoverControllesr.delegate = self; // set the delegate here to this object.
popoverControllesr.view.frame = CGRectMake(0,0, 600, 45);
popoverControllesr.view.backgroundColor = [UIColor whiteColor];
popoverController = [[mypopoverController alloc] initWithContentViewController:popoverControllesr];
popoverController.cornerRadius = 20;
if(_titles!=NULL){
popoverController.titleText = _titles;}else{
popoverController.titleText = #"Loading...";
}
popoverControllesr.address.text = absoluteString;
popoverController.popoverBaseColor = [UIColor orangeColor];
popoverController.popoverGradient= YES;
popoverController.arrowPosition = TSPopoverArrowPositionHorizontal;
[popoverController showPopoverWithTouch:event];
}