I'm looking to add a Pull to refresh feature to a UIWebView that I have in an app. I've used Pull to refresh in the past on table views, but I'm struggling to find any good tutorials/libraries to help me add it to UIWebViews specifically and this project.
I did get some of the way using PullToRefreshView by chpwn (https://github.com/chpwn/PullToRefreshView) but I can't get it detecting the drag.
Does anyone know a better plug in/library?
For me this post and code worked like a charm
http://sonnyparlin.com/2011/12/pulltorefresh-ios-5-and-arc-tutorial/
I'm new to iOS development, so this may not be the best way… but it worked for me.
I took the controller that was wrapping my WebView and I changed it to a UITableViewController (it was just a UIViewController previously) so that I could take advantage of the refreshControl property of that controller (ios6 and up). I'm not making use of the TableView inside of the UITableViewController (though, it does seem to require one to exist, which I include, but I just don't populate it). I added 2 methods to the controller:
- (void)addPullToRefresh
{
UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
refreshControl.attributedTitle = [[NSAttributedString alloc] initWithString:#"Pull to Refresh"];
[refreshControl addTarget:self.myWebView action:#selector(reload)
forControlEvents:UIControlEventValueChanged];
self.refreshControl = refreshControl;
}
- (void)stopRefresh
{
[self.refreshControl endRefreshing];
}
I put a call to [self addPullToRefresh]; in viewDidLoad, and I added a call to [self stopRefresh]; in webViewDidFinishLoad:
I got my instructions for how to use the refreshControl property of UITableViewController here.
Related
I have spent several hours. Read up everything relevant I could find on the web, but haven't been able to resolve this. I am using FBLoginView per instructions provided in https://developers.facebook.com/docs/ios/login-ui-control/
I can see FBLogin button. I click on it. It logs me in. I see callbacks loginViewShowingLoggedInUser and loginViewShowingLoggedOutUser getting called. The problem is loginViewFetchedUserInfo not getting called. So, I am unable to get any information about the user (such as name, userID, email etc).
Here is the code I am using:
CGRect loginFrame=CGRectMake(MARGIN,currentFrame.size.height-LOGINBUTTONHEIGHT,50 , 20);//width, height don't matter
FBLoginView * FBLoginView1 = [[FBLoginView alloc] init];
FBLoginView1.readPermissions = #[#"email",
#"basic_info",
#"user_location",
#"user_birthday",
#"user_likes"];
FBLoginView1.frame = loginFrame;
FBLoginView1.delegate = self;
[[self view] addSubview:FBLoginView1];
[FBLoginView1 sizeToFit];
Please help me.
It may help: I have get the same issue. For me the solution was I did not correctly assign the delegate.
Programmatically, Facebook propose you to
FBLoginView *loginView = [[FBLoginView alloc] init];
loginView.delegate = self;
But as I have set up the view via the storyboard, I could not do that. So in the inspector connector, I connect the delegate outlet to the File's Owner (I just wired the outlet the scene).
Hope it helps :)
I found the solution. Actually, loginViewFetchedUserInfo is called after loginViewShowingLoggedInUser. I was not getting loginViewFetchedUserInfo because I was dismissing modalviewcontroller from loginViewShowingLoggedInUser. So, it was not around to get loginViewFetchedUserInfo. If I don't dismiss the modalviewcontroller, I get loginViewFetchedUserInfo.
Here are the details of the solution.
I am creating FBLoginView in ViewDidLoad of a LoginViewcontroller (name of the class I implemented).
I set the delegate when I create FBLoginView (inside ViewDidLoad function)
LoginViewController is presented using presentViewController function.
The problem was happening because I was dismissing the view controller in loginViewShowingLoggedInUser. So it was not around to receive loginViewFetchedUserInfo ( loginViewFetchedUserInfo is called after loginViewShowingLoggedInUser).
The solution that worked for me is to dismiss LoginViewcontroller from loginViewFetchedUserInfo.
Hope the details helps others.
I had the same problem. In my case, delegate was not set properly. Ensure you the following lines in logincontroller:
FBLoginView *loginView = [[FBLoginView alloc] init];
loginView.delegate = self;
I have a UIViewCOntroller, and i have added 2 tableviews, and 3 textfields to it. The order of UI view controls are as follows;
1.) tableview - A - present in the first 1/2
2.) textFields
3.) tableVIew - B
I need to add the pullTorefresh functionality to the B tableView, How can i do this. I have tried several libraries (PullToRefresh, EGOTableViewPullRefresh)
Can someone give me sample code which suits my scenario.
Something like this image, (the image shows Sections, but i have done mine using seperate Tableviews, and mine has 3 textfields in between the 2 tableview). I need the 2nd tableview to have the PullToRefresh functionality.
note: Please don't tell me to try PullToRefresh, EGOTableViewPullRefresh and it doesn't address my scenario. But, if you had tried it and if it works please do help me.
iOS 6 added new control - pull-to-refresh control available for UITableViewControllers.
add following code in ViewDidLoad-
- (void)viewDidLoad
{
UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
[refreshControl addTarget:self action:#selector(refresh)
forControlEvents:UIControlEventValueChanged];
[self.tableViewB addSubview:refreshControl];
}
- (void)refresh
{
//write your code here
// for example
[self.tableViewB reloadData];
}
-(void)stopLoading
{
//after completing your action,stop loading now
[refreshControl endRefreshing];
}
I want a photo viewer in my iphone app and I liked the Three20 photo viewer. I found it somehow hard to integrate it in my own app where I have my typical UINavigationViewController. So far I succeeded in doing the following:
TTURLMap *map = [[[TTURLMap alloc] init] autorelease];
[map from:#"tt://appPhotos" toSharedViewController:[PhotoViewController class]];
[self.navigationController pushViewController:[map objectForURL:#"tt://appPhotos"] animated:YES];
The only problem is that wenn I click back to my original view, its navigation bar keeps the style of the photo viewer (transperant and shows the view under it).
How can I get back my original navigation bar?
My experience: I once used three20's PhotoViewer and every time I went back from the PhotoViewer to my other view. The system status bar remained black and transparent (while it should be with default style). I solved it by manually and programmatically changing the status bar style every time when the back action was triggered.
Yes, this is a bit of an issue for sure. A good solution, as #diwup says, is to implement a manual fix. I tend to subclass TTPhotoViewer when I need it. Not only does it help with this problem but it also makes it much easier to use I find.
If you decide to subclass, then you should use whatever variation of the following you require:
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
self.navigationController.navigationBar.tintColor = myTintColor;
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
}
However, if you don't want to subclass, you can always put the code into the - [viewWillAppear:] method of any class that comes after the photo viewer.
In my app i want to put my website's url on home screen and on clicking on it i want it to be open as a WebView.
How should i go for this.
Thanks,
Previous commenter is incorrect. You can open any hyperlink either externally with Safari or internally with a UIWebView.
Add a UIWebViewController to your project. Then, instantiate an instance of a the UIWebViewController that will be shown inside your app--you'll do this by declaring a property & synthesizing it within your main view controller (which will need to be declared as a UIWebViewDelegate), such as:
#interface MyMainViewController: UIViewController <UIWebViewDelegate> {
// Your implementation code here
}
When a user taps the button (assuming you make it a button, rather than just a text hyperlink), you instruct your app to add the UIWebView to the view stack, loading the correct link. You'll want to either do this within a modal view or within a navigation stack so your users can get back out of the web view, of course.
In your MyMainViewController implementation file, something like this:
-(void) showWebView {
// NOTE: I have not tested this, just prototyping
// off the top of my head
UIWebView *myWebView = [[UIWebView alloc] init];
myWebView.delegate = self;
NSURL *homeUrl = [[NSURL alloc] initWithString:#"http://example.com"];
NSURLRequest *homeRequest = [NSURLRequest requestWithURL:homeURL];
[myWebView loadRequest:homeRequest];
[self.presentModalViewController: myWebView animated:YES];
// Don't forget to release objects when you're done
[myWebView release]; // etc.
}
Now, this is off the top of my head from what I know and have done. But I hope you get the general idea. I offer no warranty of any kind here, but do guarantee this is entirely possible with minimal headache. If you get stuck, check out the developer references for UIWebView. Apple's docs are top-notch & show great examples to get you up and running quickly.
Best.
I'm playing around with this application I got on last months Web Designer that's a very basic RSS reader. I would like to add a refresh button to the top navigation bar that refreshes all the content in the table but can't seem to work out how to do it. I've worked out it must somehow use the [tablename Reload] function, but have got no idea how to implement it.
I'm new to all this so simple instructions are good instructions :) I know how to add the button, its linking it to and defining the actions when the user clicks it that I'm struggling with.
You can grab the code here http://www.webdesignermag.co.uk/tutorial-files/issue-162-tutorial-files/ under iPhone Apps (it's the only one).
This is what you need to do in the RootViewController.m:
In the viewDidLoad function, add a button of type UIBarButtonSystemItemRefresh, associate to it an Action and a Target, (infact, as Alan told you, you need to learn about Outlets and Actions)
UIBarButtonItem *refreshButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:#selector(refreshTable)];
self.navigationItem.rightBarButtonItem = refreshButton;
Implement refreshTable function (if not declared in .h, have to put it above viewDidLoad())
- (void)refreshTable{
[rssParser release];
rssParser = [[RSSXMLParser alloc] init];
[rssParser parseRSSFeed];
[self.tableView reloadData];
NSLog(#"table is refreshing ....");
}
Hi Graeme and velcome to SO.
For the iphone UI, you have to define outlets and actions, and use Interface Builder to link them together.
This page has some information that should hopefully get you started.
Understanding Outlets and Actions