Loading data on UITableView up scroll - ios

I would like to show activityindicator and load more content from server when scroll goes out of UITableView.
I saw it in several News Feed applications:
Does anyone know this, please help me, thanks!

Use a UIRefreshControl
- (void)viewDidLoad {
[super viewDidLoad];
self.title = #"News Feed";
self.allNewsEntries = [NSMutableArray array];
[self downloadNewsEntries];
UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
[refreshControl addTarget:self action:#selector(refreshContent)
forControlEvents:UIControlEventValueChanged];
self.refreshControl = refreshControl;
}
-(void) refreshContent {
[self.allNewsEntries removeAllObjects];
[self downloadNewsEntries];
[self.refreshControl endRefreshing];
}

Related

Adding UIRefreshControl to UIScrollView

I'm just trying to simply add a UIRefreshControl to a UIScrollview- for some reason when I pull down on the scroller, nothing happens at all. No ActivityView, no action. It just bounces back up like nothing happened.
this is what I have so far:
- (void)viewDidLoad {
[super viewDidLoad];
[scroller setAutoresizesSubviews:YES];
UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
[refreshControl addTarget:self action:#selector(handleRefresh:) forControlEvents:UIControlEventValueChanged];
[self.scroller addSubview:refreshControl];
//populate the scroller with data
[self grabData];
}
-(void)handleRefresh:(UIRefreshControl *)refresh {
// Reload my data
[self grabData];
}
This one should be helpfull
UIRefreshControl *refreshControl;
- (void)viewDidLoad {
[super viewDidLoad];
refreshControl = [[UIRefreshControl alloc]init];
[self.scrollView addSubview:refreshControl];
[refreshControl addTarget:self action:#selector(refreshData) forControlEvents:UIControlEventValueChanged];
}
- (void)refreshData {
//TODO: reload your data and end refreshing
[refreshControl endRefreshing];
}
if you are getting some data, after you have complete your receiving data then you should call endRefreshingand reloadData
What worked for me is make the refreshControl a variable of the class and then use it.
Eg:
class className: UIViewController{
var refreshControl:UIRefreshControl!
override func viewDidLoad() {
super.viewDidLoad()
self.refreshControl = UIRefreshControl()
self.refreshControl.addTarget(self, action: Selector("getPrint"), forControlEvents: UIControlEvents.ValueChanged)
refreshControl.tintColor = UIColor.whiteColor()
self.refreshControl.backgroundColor = UIColor.clearColor()
self.refreshControl?.endRefreshing()
self.scrollView.addSubview(self.refreshControl)
}
}

UICollectionView with header pull to refresh jumps

I'm using pull to refresh with UICollectionView that has an header(i don't know if the header is relevant) . When i'm pull to refresh right before the refresh part the collection view jumps down(not smoothly at all).
What could be the problem?
here is my code -
- (void)addRefresh
{
self.refreshControl = [[UIRefreshControl alloc] init];
[self.refreshControl addTarget:self action:#selector(reset) forControlEvents:UIControlEventValueChanged];
[self.refreshControl setBackgroundColor:[UIColor whiteColor]];
[self.profileCollectionView addSubview:self.refreshControl];
}
- (void)reset
{
[self.refreshControl endRefreshing];
}
I had a similar but not exactly the same problem with UIRefreshControl where the text would overlap the UIActivityIndicator of the UIRefreshControl. This would only happen the first time you would activate the UIRefreshControl. I'm not sure if this fix will help you but you can give it a try:
-(void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
//Fix for bug where spinner would overlap the text
dispatch_async(dispatch_get_main_queue(), ^{
[_refreshControl beginRefreshing];
[_refreshControl endRefreshing];
});
}

UIRefreshControl is not hiding after refresh. iOS

I am using UIRefreshControl in my table view. I have initiated refresh control in viewDidLoad:
UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
[refreshControl addTarget:self action:#selector(handleRefresh:) forControlEvents:UIControlEventValueChanged];
self.refreshControl = refreshControl;
[self.bestDealsTableView addSubview:self.refreshControl];
I have a target method for scrolling:
-(void) handleRefresh:(UIRefreshControl *) refreshControl{
[self performSelector:#selector(updateDealsList) withObject:nil withObject:nil];
}
updateDealsList method:
- (void) updateDealsList {
self.dealsService = [[BestDealsService alloc] initServiceWithDelegate:self isLocalCall:NO];
[self.dealsService fetchBestDeals];
}
In my service response method:
[self.refreshControl endRefreshing];
self.isTableViewInRefreshMode = YES;
[self.bestDealsTableView reloadData];
Now, I have two issues:
1. My refresh Control is not hiding on success response from my service.
2. If I pull table view down, I can see a refresh control, but if I scroll down again, I see a new one below the previous one.
Image for first refresh control:
Here, after scrolling down again:
Note: I am using custom TableViewCell
This is how I fixed it:
// Pull To Refresh Code
if(self.refreshControl == nil){
UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
[refreshControl addTarget:self action:#selector(handleRefresh:) forControlEvents:UIControlEventValueChanged];
self.refreshControl = refreshControl;
}
[self.myTableView addSubview:self.refreshControl];
Initialize your UIRefreshControl with:
self.refreshControl = [[UIRefreshControl alloc] init];
[self.refreshControl addTarget:self action:#selector(handleRefresh:) forControlEvents:UIControlEventValueChanged];
[self.bestDealsTableView addSubview:self.refreshControl];
and be sure to call [self.refreshControl endRefreshing];
tableView.contentOffset = CGPointMake(0, -100);

Is it possible to do pull down to refresh and load more in customized uicollectioncell in uicollectionview?

Im try the pull down to refresh in collection view but im use the (tableview pull down to refresh controller)same code for collection view. Please any one help my problem.
Firstly you can write this code in your viewDidLoad :-
- (void) viewDidLoad
{
[super viewDidLoad];
UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
refreshControl.tintColor = [UIColor blackColor];
refreshControl.attributedTitle = [[NSAttributedString alloc] initWithString:#"Pull to Refresh"];
[refreshControl addTarget:self action:#selector(refreshControlAction) forControlEvents:UIControlEventValueChanged];
[collectionView addSubview:refreshControl];
}
Now add a target
- (void) refreshControlAction
{
// Enter your code for request you are creating here when you pull the collectionView. When the request is completed then the collectionView go to its original position.
}

how to move to the new view fast in ipad application

I have many view controller when i click on tableView cell it move to new view controller problem is that it takes alot of time to move to the next view may be due to view which is to load fetches data from server here is my code for the view which loads
- (void)viewDidLoad {
appDelegate = (MultipleDetailViewsWithNavigatorAppDelegate *)[[UIApplication sharedApplication] delegate];
UIImageView *bottomImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Nav.png"]];
[bottomImageView setFrame:CGRectMake(0,690,1024,34)];
[self.view addSubview:bottomImageView];
UIButton *button1=[UIButton buttonWithType:UIButtonTypeCustom];
[button1 setFrame:CGRectMake(10.0, 2.0, 88, 40.0)];
[button1 addTarget:self action:#selector(loginPressed) forControlEvents:UIControlEventTouchUpInside];
[button1 setImage:[UIImage imageNamed:#"logoutN.png"] forState:UIControlStateNormal];
UIBarButtonItem *button = [[UIBarButtonItem alloc]initWithCustomView:button1];
self.navigationItem.rightBarButtonItem = button;
self.title=#"Catalog";
popImageView.hidden=YES;
passwordLabel.hidden=YES;
userLabel.hidden=YES;
userNameTextField.hidden=YES;
userPasswordTextField.hidden=YES;
signInButton.hidden=YES;
tableView.hidden=NO;
searchBar.autocorrectionType = UITextAutocorrectionTypeNo;
searching = NO;
letUserSelectRow = YES;
if(!categoryArray){
categoryArray =[[NSMutableArray alloc] init];
}
if(!userArray){
userArray =[[NSMutableArray alloc] init];
}
if(!subCategoryArray){
subCategoryArray =[[NSMutableArray alloc] init];
}
if(!subCategoryArrayOne){
subCategoryArrayOne =[[NSMutableArray alloc] init];
}
if(!subCategoryArrayTwo){
subCategoryArrayTwo =[[NSMutableArray alloc] init];
}
[self setUpData];
[self setUpDataSub];
[self setUpDataSubOne];
[self setUpDataSubTwo];
int count=[appDelegate.coffeeArray count];
NSLog(#"Arrays Content Are %d",count);
tableView.backgroundView = nil;
[super viewDidLoad];
}
is there any way so that view loads fast
Your view is not loading fast because of I guess those data set operation in viewDidLoad method . I think those are :
[self setUpData];
[self setUpDataSub];
[self setUpDataSubOne];
[self setUpDataSubTwo];
The one thing you could do is to move this operations to perform on the background thread . For that move this operations to the separate function and call that to perform on background from the view did load method :
-(void)dataOperations
{
[self setUpData];
[self setUpDataSub];
[self setUpDataSubOne];
[self setUpDataSubTwo];
}
and in viewDidLoad call this function in background:
[self performSelectorInBackground:#selector(dataOperations) withObject:nil];
Or you can directly call those method from viewDidLoad like :
[self performSelectorInBackground:#selector(setUpData) withObject:nil];

Resources