Pull to Refresh (ios) - iphone

I recently implemented pull to refresh here: https://github.com/leah/PullToRefresh. It kind of works however it gets stuck with a spinning activity indicator. Their is also no text to the right of the arrow. What am I doing wrong? Thanks!

Without code there's not much anyone can say, but maybe try a different implementation of Pull To Refresh, like the enormego (EGO) version, the code is at github, here
It's used in the Facebook app so it definitely works.

Apple has introduced UIRefreshControl in iOS6. You can integrate it in your UITableViewController using
- (void)viewDidLoad {
[super viewDidLoad];
// Initialize Refresh Control
UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
// Configure Refresh Control
[refreshControl addTarget:self action:#selector(refresh:) forControlEvents:UIControlEventValueChanged];
// Configure View Controller
[self setRefreshControl:refreshControl];
}
the refresh: method will trigger the update and you can stop it in your API callback using:
[(UIRefreshControl *)sender endRefreshing];

I am new to iOS development and I was trying to implement the pull to refresh in iOS 6. Well looking for a solution, I stumbled across this blog post and found it to be very helpful, http://www.intertech.com/Blog/Post/iOS-6-Pull-to-Refresh-(UIRefreshControl).aspx. It lays out the steps to implementing pull to refresh in a way that is easy to follow. Anyone looking to do this themselves in iOS 6 should check out the blog.
The UIRefreshControl is only useable with a Table View currently. There are a few steps to follow to successfully add a refresh control:
1.
Create a callback method to handle your refresh logic. The callback method should be invoked when a user pulls down on the table view. The signarture of the method should take one parameter: a pointer to the UIRefreshControl.
Note: Steps 2-4 are all done within the Table View Controller’s viewDidLoad method.
2.
Instantiate the UIRefreshControl with a basic "alloc/init".
3.
Connect an action to the refresh control to invoke your callback method when the ValueChange event is fired.
4.
Add the refresh control to the Table View Controller's "refreshControl" property.

I prefer the EGO implementation than the leah one because it does not require a subclass of your view controller. The original EGO one in github is a bit of a mess with no .gitnore file and lots of .DS_Store files added unnecessarily. Take a look at some of the many forks and pick one.
The "emreberge" fork looks like a good version, better file organisation and documentation too!
https://github.com/emreberge/EGOTableViewPullRefresh

I found this library very useful, fancy and up-to-date: https://github.com/Yalantis/Pull-to-Refresh.Rentals-iOS
(Recommendations from other answers seem old and not maintained)

Now, with newer versions of iOS than the above stated iOS 5 you can use: UIRefreshControl.
There is a really good tutorial on creating your own custom pull to refresh for your iOS Application: http://ios-blog.co.uk/tutorials/how-to-add-a-custom-pull-to-refresh-in-your-ios-application/

You can use : https://github.com/ngocbinh02/httablekit
Support iOS 5.0 or later
Pull to refresh tableview
import <HTTableKit/TableKit>
....
//like UIRefreshControll
[tableview setPullToRefreshControlType:UITableViewRefreshControlTypeSystem];
[tableview setPullToRefreshModeEnable:YES beginHandler:^{
// to do here when pulling to refresh
}];
Dismiss pull to refresh tableview
import <HTTableKit/TableKit>
....
[tableview dismissPullToRefreshEndHandler:^{
// to do here when dismissing
}];

Here's our tutorial on Custom Pull-to-Refresh controls, with code for Objective-C and Swift: http://www.jackrabbitmobile.com/design/ios-custom-pull-to-refresh-control/
To add additional text or images, as you mentioned, add them into self.refreshLoadingView in the setupRefreshControl or scrollViewDidScroll methods (from the tutorial).
Let me know if that helps!

Related

Best way to disable UIViewController interaction and show activity indicator while loading data from web service or core data?

Question says it all.
Is there a best recipe to follow to disable user interaction and show a activity indicator while fetching data from a web service or loading data from a core data fetch operation?
I'm using ASIHTTPRequest, JSONKit and Core Data in my particular app so any sample code using those Apis would be preferred.
Thanks - wg
Create a UIView with transparent background and that takes the whole screen.
It will intercept the interaction and won't let the user tap on the other items on the screen.
Then you can add an UIActivityIndicator (and even a UILabel) as a subview of this transparent fullscreen view or whatever you need.
Note that there are multiple existing projects like SVProgressHUD that do that already too and that I strongly recommand.
A very very simple and easy way to accomplish both tasks is using MBProgressHUD.
Check it's repository in Github
Example usage:
+ (MBProgressHUD *)showHUDAddedTo:(UIView *)view animated:(BOOL)animated;
+ (BOOL)hideHUDForView:(UIView *)view animated:(BOOL)animated;
These two class methods will show/hide a simple activity indicator with a translucid background.
It also has properties to show text, progress and a good delegate.
Use the up mentioned HUD control on rootViewContoller. It will not let user to interact with UI.

Close tableview in ViewBasedApplication

probably a very simple question but can't find the right answer anywhere. I am using XCode 4 and working on an iphone app, which probably sums up all the info that I need to provide.
Here it is:
- I created a ViewBasedApplication
- At some point depending on the user input, I load a TableView
But now how on Earth do I add a button or something to return? Note: I can't use a NavigationBased app, that would be easier but would not work for me.
Help anyone?
If you used a UITableViewController, you may want to use a UIViewController instead. In the UIVeiwController, you can add a UITableView along with your own UINavigationBar or, if you don't want to use a UINavigationBar, you could leave room for some type of custom UIButton. Either the UINavigationBar button or your custom UIButton action could trigger a close of your UIViewController.
If you add the UIViewController as a subview, then Cyprian's [self removeFromSuperView]; would work. If you present as a modal as Jamie suggests, you could use [self dismissModalViewControllerAnimated:YES];.
Well I don't know you code but you could always call
[self removeFromSuperView];

three20 - TTTableViewController Memory warning gives blank screen, how to fix?

This is driving me nuts. I am using three20's TTTableViewController and when I get a memory warning, the screen goes white. Now, after reading on the three20 google group is seems that the tableView got released. But, I cannot for the life of me figure out a check to see if that is the case, then create it again.
I was using the following because I thought it would fix the issue, but it seems that it doesn't satisfy the if statement:
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
// If we don't have a datasource we need to reset it
if (!self.dataSource) {
// Create datasource again
}
}//end
Does anyone know what to do when this happens? The google group has been no help.
Are you subclassing TTTableViewController? I haven't used it before, but assuming it's just like UITableViewController...
How does your "viewDidUnload" look like? Are you releasing the tableview here? If so, you need to create tableview in viewDidLoad to match it.
No need to check if dataSource is available in viewDidAppear, because if you read View programming guide, it explains that memory warning will call "viewDidUnload" to give you a chance to clean up data that are created in "viewDidLoad".
i had the same issue and it drove me crazy as well.
Nobody mentions it in the three20 docs, but you shouldn't use UIViewController's initWithNibName function to add subviews. If you do, a memory warning will release these subviews.
Try to move your code from initWithNibName function to viewDidLoad function. I have noticed that some code need to be kept in the initWithNibName, such as navigation styles. However, any subviews added to the controller's view should be in the viewDidLoad function.
In general you should be careful to set up views in viewDidLoad rather than the class constructor. For instance, you should set up your launcher view in viewDidLoad rather than the constructor of your launcher view controller, otherwise your launcher will become empty after a memory warning.
In the case of TTTableViewController however this does not (usually) apply because you don't set up the table view manually. I had the same problem you had, and eventually tracked it down: I had redefined viewWillDisappear: and forgot to call [super viewWillDisappear:animated]. This meant that some of the flags that the Three20 controller maintains about the state of the view were not updated correctly.
I also found that it was beneficial to redefine didReceiveMemoryWarning to call [self setEditing:NO] before calling super; I found that the state of the table view got confused otherwise (this is not relevant if you don't use edit mode for your table).
Finally, there is a bug in Three20 which means that tables in loading/empty/error mode will not be restored properly; see a discussion in the blog post by TwoCentStudios and a proposed fix on github.

How do I get the items to refresh in the Flowcover example?

The Flowcover example code provides an OpenGL ES implementation of the coverflow effect. How can I refresh the images used in that example?
I have tried [view reloadData]; but that didn't refresh the images. What else should I do?
Could you elaborate a bit on where you want to refresh the images? Are you reloading a new set of images you want to display?
Note that there is a cache in the class FlowCover that you might need to empty. There is currently no interface to do just that so you might want to add the next method to the class DataCache:
- (void) emptyCache {
[fDictionary removeAllObjects];
[fAge removeAllObjects];
}
Remember to send setNeedsDisplay to the View after modifying any data it depends on.

Call an onclick method from one view to another iphoneprogess hub iphone sdk

I have a view with a button which downloads files when clicked.
Question I have is is it possible to call that click method from another view>
THanks
You have a method there. Something like onBtnClk. You can create in another view an instance of your viewController, that contains this method and send [myViewController onBtnClk].
This may be a good case to have some other class(maybe a singleton?) handle downloads, then have your click: method interact with the downloading class.
I know that everyone hates singletons, but this may be a good time to use one.