I got a static tableList of Categories on a view controller (called CategoriesViewController ) in main storyboard, this contain the categories of the Blog shown in a webView in fistViewController.
When I click (or tap) in a Category it must to send me to webView Page and change the URL (eg mainpage is www.example.com and category is www.example.com/category)
I've just made a simple webView in first page view like:
- (void)viewDidLoad {
[super viewDidLoad];
NSString *fullURL = #"http://www.example.com";
NSURL *url = [NSURL URLWithString:fullURL];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[_webView loadRequest:requestObj];
}
How can I interact with elements in another controller and change NSURLRequest appending the category after slash?
Should I get the elements on the Table View as ID?
And what's the code to archieve this?
As I understood that is a TableView. So you need to implement the method didSelectRowAtIndexPath and I believe you have an array of those categories. so you need to get the indexPath.row (indexPath is an argument in this method) and pass it along to the next view controller by appending it to the initial URL.
Related
From firstViewController I send a url to load on secondViewController. The url loads correctly. They, I press cancel button to go back to firstViewController:
[self dismissViewControllerAnimated:YES completion:nil];
Then again if I come back to secondViewController from firstViewController, I see a blank space with horizontal scrollbar.
I've used the following code to load url:
NSString *urlAddress = #"http://www.apple.com";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[self.myWebView loadRequest:requestObj];
I've implemented webview delegate methods and they are being called without any problem. for example following methods are called:
– webViewDidStartLoad:
– webViewDidFinishLoad:
Even there is no error to load and I've printed html source codes in -webViewDidFinishLoad and it Logged right codes.
My device iOS version is: iOS 9.3.2
Update:
The same app works well on my simulator. But doesn't work on real device.
I m just trying to fix all the contents of html according to the device screen.
I have to put html data at proper place for iPhone & iPad in webview.
Please help me!!!
I am going to assume that this question is a very basic one.
Suppose that you have placed a UIWebView in a view in your storyboard, and you have set layout constraints so that the UIWebView fills the view.
Then
Add an IBOutlet to your view controller, and connect it to the web view.
In the view controllers viewDidLoad: method, tell the web view what to display. Here is an example:
-(void)viewDidLoad {
[super viewDidLoad];
NSURL* url = [NSURL URLWithString:#"http://www.apple.com"];
NSURLRequest* r = [NSURLRequest requestWithURL:url];
[_webView loadRequest:r];
}
This loadRequest: call is asynchronous, meaning that the page may not show up immediately.
If this is not answering your question, please add more information.
I have been using AMSlidemenu with multiple AMSlideMenuContentSegues.
They all work fine at the moment as they just display a label.
The first view controller I have added a web view and given it its own custom class .h and .m file which point to a url but every time I launch the application crashes.
.....
- (void)viewDidLoad
{
NSURL *url = [NSURL URLWithString:#"http://google.com"];
NSURLRequest *requestURL = [NSURLRequest requestWithURL:url];
[websiteWebview loadRequest:requestURL]; **Thread 1: Breakpoint 1.1**
[super viewDidLoad];
// Do any additional setup after loading the view.
}
......
I dont understand whats happening ... I m a novice when it comes to Xcode so any help will be appreciated.
I hope I have contextualized my problem.
I am using storyboard in xcode to desgin my app instead of xibs. This is my first time using them and i have a question. Right now I have multiple TableViews all with multiple cells inside. What i am trying to achieve is to click on the cell and that will then load a PDF. Each cell has a pdf that it should open. Instead of using segues and linking each tableview cell to its OWN view controller which would be very redundant. Is there some code i could put it a (I think UIWebView) that would let me see what cell was clicked and load the respective PDF. Is this possible? THank you!
You can use the master detail view controller template for this, which will be easiest to set up, then you can disable the edit and the add buttons and set up your list of PDF's with an array.
Once they are all set up it will set the detail items automatically, if you don't have core data enabled you can access it by:
[self.detailItem description];
This gives you the name of the row that was clicked, which then you can use that to load the PDF to the UIWebView. The web view can load the PDF to view with:
NSString *pdfName = [NSString stringWithFormat:#"%#", [self.detailItem description]];
NSString *path = [[NSBundle mainBundle] pathForResource:pdfName ofType:#"pdf"];
NSURL *url = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[pdfViewer loadRequest:request];
[pdfViewer setScalesPageToFit:YES];
Just be sure to declare pdfViewer as your UIWebView in the detail view controller
I have a UIViewController with a UIWebView where I'm placing a PDF.
The issue I'm facing is when I click on a table cell to show the PDF it does not show the first time however if i go back to the table and click on the cell again it appears.
I call the PDF to get loaded using the following:
if ([indexPath row] == 2)
{
NSString *path = [[NSBundle mainBundle] pathForResource:#"myFirstPdf" ofType:#"pdf"];
NSURL *url = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webViewVC.webView loadRequest:request];
webViewVC.parent = _parent;
[_parent pushViewController:webViewVC];
}
The webViewVC itself I allocate using an initWithNib which has the UIWebView - nothing fancy there, simply a UIWebView with a IBOutlet.
Any ideas?
I think you should try 2 things:
(1) First, try loading the PDF from the web view controller. This is really the standard way to do this, rather than doing a load request for a web view that is not even on screen yet. All outlets are guaranteed to be loaded only in viewDidLoad of the controller.
(2) Second, try making use of the UIWebViewDelegate. For example, you could call setNeedsDisplay on the web view once loading is finished.
My idea : the first time you try the action your "webViewVC" hasn't been loaded yet, so webViewVC.webView is nil
the second time as you have displayed the webViewVC in your first attempt, it has been loaded, so webViewVC.webView isn't nil;
create a property on your webViewVC where you will set your request
and on your webViewVC viewWillAppear method do your [self.webView loadRequest:self.request];