I have an app. In this on the click of an Upload button a UITableView appears inside a UIPopOverController with a few entries. On clicking on any of these entries, a corresponding site should open in the wUIWebView of my UIDetailView of SplitView app.
I am using the following lines of code ::
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Navigation logic may go here. Create and push another view controller.
hUrl = [kk objectAtIndex:indexPath.row];
hUrl = [Url stringByReplacingOccurrencesOfString:#" " withString:#"_"];
NSString *hisPage= [[NSUserDefaults standardUserDefaults] stringForKey:#"url_preference"];
Page = [hisPage stringByAppendingString:#"/index.php/"];
Page = [hisPage stringByAppendingString:hUrl];
NSURL *Url = [NSURL URLWithString:Page];
NSLog(#"%#", Url);
NSURLRequest *request = [NSURLRequest requestWithURL:Url];
self.detailViewController.webView.scalesPageToFit = YES;
[self.detailViewController.webView loadRequest:request];
}
The UITableView appears inside a UIPopoverController. However, I am unable to load the corresponding webPage. Can someone help me to sort this out ?? Thanks and regards.
Per your answer to my comment, the proper procedure to follow in this scenario is as follow:
Implement a delegate method protocol for your popOverController instant.
In didSelectRowAtIndexPath, call the delegate method back to the parent view controller (where your Upload button located). And passing back the Url string as a parameter.
From the parent view controller, dismiss the popover and using the passed back Url to prepare your detailViewController and then push it onto display stack.
An example of delegate method can be found in this SO .
Related
I have a tabbed application, with a tab that contains a UIWebView and a second tab with a Table View Controller.
I'm trying to make it so that when I click on a row in the table it takes me to my other tab and loads a web page.
Here's my storyboard:
This is in my implementation for the web view:
-(void)loadAViewer:(NSURL*)viewerURL
{
NSURLRequest *requestObj = [NSURLRequest requestWithURL:viewerURL];
[sfnViewer loadRequest:requestObj];
}
And then in the table view controller:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//Get the URL from plist
...
//Generate url, pass it in and switch to web view tab
viewerURL = [NSURL URLWithString:[NSString stringWithFormat:#"%#%#/viewer?username=%#&pw=%#&%#", web, loc, user, pass, params]];
ViewerFirstViewController *viewerWebView = [[ViewerFirstViewController alloc] init];
[viewerWebView loadAViewer:viewerURL];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
[self.tabBarController setSelectedIndex:0];
}
Currently nothing happens. I'm taken to the other tab but with a blank UIWebView - no page loads but it doesn't crash either.
//Edit - Changes made based on answer from Steve
Based on this I've added
#property (strong, nonatomic) NSURL viewerUrl;
in my .h file for the UIWebView tab.
I've synthesized it in the .m and added this to my viewDidLoad method.
NSURLRequest *requestObj = [NSURLRequest requestWithURL:viewerURL];
[sfnViewer loadRequest:requestObj];
In the Table View Controller I'm now doing this.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//Get the URL from plist
...
//Generate url, pass it in and switch to web view tab
viewerURL = [NSURL URLWithString:[NSString stringWithFormat:#"%#%#/viewer?username=%#&pw=%#&%#", web, loc, user, pass, params]];
ViewerFirstViewController *viewerWebView = [[ViewerFirstViewController alloc] init];
[viewerWebView setViewerUrl:viewerURL];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
[self.tabBarController setSelectedIndex:0];
}
Still to no avail.
It's probably not loading because when you call loadAViewer: the view itself hasn't been loaded yet so the sfnViewer outlet won't be hooked up to the UIWebView in your storyboard.
You can confirm this by checking if sfnViewer is nil in loadAViewer:.
If this is the case you will have to define an NSURL property on the ViewerFirstViewController and assign to that instead of calling loadAViewer:. Then in the viewWillAppear: method you should load the URL into sfnViewer.
However this will result in the web view being reloaded each time the tab is accessed, you could avoid this by checking if viewerURL is different from the URL currently in use in the web view: [sfnViewer.request.URL isEqual:self.viewerURL], if it is the same then don't create/load the request.
I'm trying create a subclass of UIActivity to add a custom button to a UIActivityViewController. I want this custom button to be able to open a link without leaving the application. I've found numerous solutions that allow for opening things in safari, but I can't figure out if it is possible to just open a UIWebview inside my app (Modal view perhaps?).
I've tried creating a `UIWebview in the delegate method to handle the click, but since this isn't a viewcontroller I can't add it to the view hierarchy.
- (void)prepareWithActivityItems:(NSArray *)activityItems{
UIWebView *webView=[[UIWebView alloc] initWithFrame:CGRectMake(0,0,320,480)];
NSURLRequest *urlRequest;
NSURL *urlforWebView;
urlforWebView=[NSURL URLWithString:#"http://www.google.com"];
urlRequest=[NSURLRequest requestWithURL:urlforWebView];
[webView loadRequest:urlRequest];
}
// example:Need to add your webview to your mainview first
UIWebView *webView = [[UIWebView alloc] init];
[webView setFrame:CGRectMake(0, 0, 320, 460)];
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://google.com"]]];
[[self view] addSubview:webView];
I believe this project implements just what you would like to do but it opens in safari: https://github.com/davbeck/TUSafariActivity Good for starting point.
The activity itself cannot open the view as it is not connected to the controller view hierarchy. You need some way to tell the host controller that the user has selected your activity. The easiest way to do this is through notifications:
The view controller registers for notifications with a given identifier.
The activity posts this notification if performed.
The notification is processed by the activity in the handler method and it opens the web view.
Don't forget to unregister the view controller from the notification center if the controller is being removed from the navigation stack.
There are lots of examples for using notifications, like this Send and receive messages through NSNotificationCenter in Objective-C?
Try this
UIPlainViewController here is just a custom UIViewController with a WebView added to it. Implement (UIViewController *)activityViewController in your derived UIActivity class as such:
(UIViewController *)activityViewController {
NSString *page = #"some url";
NSURL *url = [[NSURL alloc] initWithString:page];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];
[((UIPlainViewController*)self.plainViewController).webView loadRequest:request];
return self.plainViewController;
}
i am making an iPad application,
i want to load 2 webPage on single UIWebView one after another,
1st webpage should come when i load my application,and 2nd webpage should come on click of cell of tableView,
so,inside my didLoad method i am writing this (1st webpage),
NSString *urlAddress = #"http://www.google.com";
//Create a URL object.
NSURL *url = [NSURL URLWithString:urlAddress];
//URL Requst Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
//Load the request in the UIWebView.
[webView loadRequest:requestObj];
it works fine..
but on the same page on same webview on click of cell of tableView i want to load another page,(2nd webpage)
i written code for loading 2nd webPage,
here is the code snippet for 2nd webPage,
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
DatabasesViewController *nextController=[[DatabasesViewController alloc]initWithNibName:#"DatabasesViewController" bundle:nil];
[self.navigationController pushViewController:nextController animated:YES];
[nextController changeProductText:[a objectAtIndex:indexPath.row]];
[nextController changeProductText1:[b objectAtIndex:indexPath.row]];
[nextController changeProductText2:[d objectAtIndex:indexPath.row]];
}
when i selects a cell inside tableView,
it navigates to new view, i don't want to navigate, i want to stay on same page what changes should i do in above function ?
in above function changeProductText,changeProductText1,changeProductText2, are three IBAction and a,b,d are my array names.
- (IBAction) changeProductText:(NSString *)str{
l1=#"http://ipad.appel.com/indexcharts.aspx?id=";
l2=str;
NSString *str1 = [l1 stringByAppendingString:l2];
NSURL *url2=[NSURL URLWithString:str1];
NSURLRequest *req2=[NSURLRequest requestWithURL:url2];
[webView loadRequest:req2];
}
when i click on cell of tableView webView is not displaying,
do i need to clear webpage or reload webpage something like that ?
Help Me Guys, Thanx in Advance !!
I think You can use the UISplitViewController for this issue.
EDIT : Now check out the code like this..
-(void)tableView:(UITableView *)tableView didSelectedRowAtIndexPath:
(NSIndexPath *)indexPath
{
NSString *urlString = [siteAddress objectAtIndex : indexPath.row];
detailViewController.webView.scalesPageToFit= yes;
NSUrl *url = [NSUrlRequest requestWithURL : url];
[detailViewController.webView loadRequest : request];
}
[self.navigationController pushViewController:nextController animated:YES];
This navigates you away from the page. It pushes a new view onto the navigation stack. Get rid of it if you don't want to do that.What is this a splitView?
I have a UIPopoverController that has a UITableView that is populated. I am trying to pass the information from the popovercontroller to the superview. The tableview that is placed in the popovercontroller is receiving the information with the didSelectRow method but the information is not transferring to the textView placed in the superView.
Below is the code I use to try and place the selected user in the textview and underneath that is the Superview code where I try to take the string and place it into the actual field when the index is clicked. I know my issue is I am not telling my superView that the row was touched and to send that information into the field but I have searched and con not find a good explanation on how to attempt this.
If anyone has any suggestions that would be great!
thanks
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
*)indexPath {
if (indexPath){
NSString *selectedUser = [(Tweet*)[Friend objectAtIndex:indexPath.row]
followingScreenName];
TwitterFollowersTimline *textBox = [[TwitterFollowersTimline alloc]
initWithNibName:#"TwitterFollowersTimeline" bundle:[NSBundle mainBundle]];
textBox.selectedFriend = selectedUser;
NSLog(#"%#", selectedUser);
[textBox release];
textBox = nil;
}
}
In my SuperView
selectedFriend = [[NSString alloc] init];
creatTweetText.text = [NSString stringWithFormat:#"#%#", selectedFriend];
In order to pass information from the View Controller of the popover you're going to want to set up a delegate. Here's a link to Apple's documentation and also a good guide example.
https://developer.apple.com/library/content/documentation/General/Conceptual/DevPedia-CocoaCore/Delegation.html
http://iosdevelopertips.com/objective-c/the-basics-of-protocols-and-delegates.html
Essentially when you create the View Controller that houses the methods for your table view, you'll want to give it a delegate. Then once a cell is selected in your table view, you'll be able to send a call to your delegate with any information you need.
I got a UITabBarController and one of the bar items is a Navigation Controller with some buttons on it.
One of the buttons opens up a urlRequest and load it in a UIWebView.
NSURL * url = [NSURL URLWithString:myUrl];
NSURLRequest * urlRequest = [NSURLRequest requestWithURL:url];
UIWebView * web = [tView wView];
[web setScalesPageToFit:YES];
[web loadHTMLString:#"Loading" baseURL:nil];
[web loadRequest:urlRequest];
[self.navigationController pushViewController:tView animated:YES];
For some reason when i click the button for the first time nothing happens.
I used the UIWebViewDelegate protocol to debug it like so:
- (void)webViewDidStartLoad:(UIWebView *)webView
{
NSLog(#"webViewDidStartLoad");
}
When i click the button nothing happens, and i don't see the NSLog message.
When i hit back and click the button again, i see the debug and everything works just find.
Any idea what causing this ?
P.S if i put the :
[self.navigationController pushViewController:tView animated:YES];
in the webViewDidStarLoad method the application just hang, since it's not loading it on the first click.
You need to make sure that tView's view has been loaded. When a viewController is instantiated, its view (and all of it's IBOutlets) are all nil, and remain that way until the view is loaded.
You have two options: move your load stuff into tView's -viewDidLoad method, or force the view to load before calling [tView wView] by, for example, calling [tView view] (this will force the XIB file to be loaded, and all outlets to be connected.