UA-17470720-3

Jump to content


Photo
- - - - -

pull to refresh


  • Please log in to reply
15 replies to this topic

#1 Brian Hammond

Brian Hammond

    Starting Out

  • STV 2.0
  • Pip
  • 7 posts
Reputation: 0
Neutral

Posted 25 January 2011 - 07:24 PM

Does anyone have a working example of "pull to refresh"? I just started looking at EGOTableViewPullRefresh a bit ago.

So far, what I've seen either requires me to subclass UITableViewController or act as a proxy for UIScrollViewDelegate, neither of which seem possible with STV.

Thoughts?

#2 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 26 January 2011 - 03:29 AM

Hi Brian,

This is an area that we're intending to tackle after our next STV 2.0 release. As for now:

I just started looking at EGOTableViewPullRefresh a bit ago.


I've had a quick look at their source code and I see no reason that it shouldn't be working with STV. Please tell me if you're having any issues integrating it.

So far, what I've seen either requires me to subclass UITableViewController or act as a proxy for UIScrollViewDelegate, neither of which seem possible with STV.


It's perfectly possible with STV to provide your own subclasses of UITableViewController or UIViewController. In fact, almost every sample application we ship does that. It's even possible for you to subclass UITableView if you want. STV is completely decoupled from your view controller and your table view. Again, please tell me if you're having any issues with doing that.

#3 Brian Hammond

Brian Hammond

    Starting Out

  • STV 2.0
  • Pip
  • 7 posts
Reputation: 0
Neutral

Posted 26 January 2011 - 09:26 AM

I am new to STV but I don't see how I can, in the case of EGOTableViewPullRefresh, act as a proxy and tell it about scroll events.

See this.

In my case I have basically this:

@interface MyController : UIViewController <SCTableViewModelDataSource, SCTableViewModelDelegate> 
{
  UISearchBar *searchBar;
  UITableView *tableView;	
  SCArrayOfObjectsModel *tableModel; 
  NSMutableArray *items;
...
}

//...

- (void)viewDidLoad 
{
	[super viewDidLoad];
	
	items = [NSMutableArray array];	 // ...

	SCClassDefinition *classDef = [SCClassDefinition definitionWithClass:[Something class] 
											   autoGeneratePropertyDefinitions:YES];	
	classDef.titlePropertyName = @"name";

	tableModel = [[SCArrayOfObjectsModel alloc] initWithTableView:self.tableView 
											   withViewController:self 
														withItems:items 
											  withClassDefinition:classDef];
tableModel.delegate = self;
tableModel.searchBar = self.searchBar;
tableModel.searchPropertyName = @"name";
...
}

Thus, where might I be able to subclass UITableViewController here as in the linked EGO demo? In my case the withViewController is self which is a UIViewController. I just don't see where I can setup the table model with a subclass of UITableViewController.

I looked through the samples -- the closest one to my situation is the PeopleViewController in Core Data App. How would you subclass UITableViewController in this case?

Again, I'm new to STV since a few days so forgive me if this is something obvious! Thanks.

#4 Brian Simmons

Brian Simmons

    Starting Out

  • STV 2.0
  • Pip
  • 0 posts
Reputation: 0
Neutral

Posted 17 February 2011 - 11:23 AM

Check out this Pull To Refresh implementation:
https://github.com/leah/PullToRefresh

Pretty nice in my opinion. And easy to use.

#5 Brian Hammond

Brian Hammond

    Starting Out

  • STV 2.0
  • Pip
  • 7 posts
Reputation: 0
Neutral

Posted 01 March 2011 - 12:41 PM

Yes that's nice too.

But EGO is "better" since it's used in Three20 and a bunch of other places.

I put this on the back burner for a while... but now I need to look into it again.

I have a UIViewController that has a UITableView contained within its view, among other things.

When I create the SC table model I'm setting its view controller to the UIViewController... I don't have a UITableViewController for instance.

I suppose I need to create a UITableViewController subclass, set the table view to the contained table view, and proxy the scrolling events to EGO.

Then again, I think tarekskr was adding this pull to refresh stuff to the next version?

#6 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 01 March 2011 - 12:53 PM

Hi Brian,

STV 2.0 (due before mid March) will not include pull to refresh. After 2.0, we're planning another minor release that will address several issues relating to asynchronous data access, one of which will probably be the popular "pull to refresh".

#7 Brian Hammond

Brian Hammond

    Starting Out

  • STV 2.0
  • Pip
  • 7 posts
Reputation: 0
Neutral

Posted 01 March 2011 - 12:55 PM

OK!

Would you mind taking a look at the earlier posts in this thread? I need to launch with this feature in the next week.

Thanks!

#8 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 01 March 2011 - 01:12 PM

I am assuming the following is your question:

I just don't see where I can setup the table model with a subclass of UITableViewController.


This is actually the case with almost all our sample applications. For example, please have a look at the "Core Data App" sample application. If you navigate to TasksViewController.h, you'll find that we've created a class called TasksViewController, which itself is a subclass of UITableViewController. In TasksViewController.m, we've created the model and normally passed the view controller to it. Please tell me if this answers your question.

#9 Brian Hammond

Brian Hammond

    Starting Out

  • STV 2.0
  • Pip
  • 7 posts
Reputation: 0
Neutral

Posted 01 March 2011 - 01:28 PM

I have a tableView inside a UIViewController, not a UITableViewController. In fact, I have no UITableViewController.

@interface Foo : UIViewController <SCTableViewModelDataSource, SCTableViewModelDelegate> {
  SomeOtherView *otherView;
  UITableView *tableView;
  SCArrayOfObjectsModel *tableModel;
}
...
@end

// .m

...

	tableModel = [[SCArrayOfObjectsModel alloc] initWithTableView:self.tableView 
											   withViewController:self 
														withItems:ratings 
											  withClassDefinition:ratingsClassDef];


How can I proxy scrolling on tableView to EGO's pull to refresh?

I suppose I add a subclass of UITableViewController, set its tableView to my tableView, and pass it to withViewController?

#10 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 01 March 2011 - 03:19 PM

Hi again Brian,

I've downloaded the demo application from the EGOTableViewPullRefresh framework, then I modified it to use STV. Here is the new project (please place your own STV files in the "Sensible TableView" folder)

[file name=TableViewPull.zip size=88301]http://sensiblecocoa...bleViewPull.zip[/file]

Now there is only one remaining problem: a deeper study of the EGO framework reveals that they implement both the "scrollViewDidScroll" and "scrollViewDidEndDragging" delegate methods. Since STV overrides the UITableView's delegate and dataSource, EGO's implementation does not get called.

To help you overcome this, we can implement these two methods as part of our SCTableViewModelDelegate. Are you able to wait till mid-March, when we'll be releasing our STV 2.0 final version?

#11 Brian Hammond

Brian Hammond

    Starting Out

  • STV 2.0
  • Pip
  • 7 posts
Reputation: 0
Neutral

Posted 01 March 2011 - 05:47 PM

Yes, that is the problem I've been trying (poorly) to illustrate.

No, I will modify STV in the interim. I have to get this feature into my client's app within the next 5-6 days.

Thanks! B)

#12 Brian Hammond

Brian Hammond

    Starting Out

  • STV 2.0
  • Pip
  • 7 posts
Reputation: 0
Neutral

Posted 01 March 2011 - 06:35 PM

OK that was easy enough...

Here you go..... I didn't proxy all of UIScrollViewDelegate but just enough to get EGO pull to refresh working.

It works fine.

Thanks for the heads up about this coming later.


In SCTableViewModel.h in SCTableViewModelDelegate


//////////////////////////////////////////////////////////////////////////////////////////
/// @name UIScrollView related methods
//////////////////////////////////////////////////////////////////////////////////////////

- (void)tableViewModel:(SCTableViewModel *)tableViewModel
   scrollViewDidScroll:(UIScrollView *)scrollView;

- (void)tableViewModel:(SCTableViewModel *)tableViewModel
	scrollViewDidEndDragging:(UIScrollView *)scrollView
	willDecelerate:(BOOL)decelerate;

In SCTableViewModel.m in SCTableViewModel

#pragma mark -
#pragma mark UIScrollViewDelegate Methods

- (void)scrollViewDidScroll:(UIScrollView *)scrollView 
{
	if([self.delegate conformsToProtocol:@protocol(SCTableViewModelDelegate)]
	   && [self.delegate respondsToSelector:@selector(tableViewModel:scrollViewDidScroll:)])
	{
		[self.delegate tableViewModel:self scrollViewDidScroll:scrollView];
	}
}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
	if([self.delegate conformsToProtocol:@protocol(SCTableViewModelDelegate)]
	   && [self.delegate respondsToSelector:@selector(tableViewModel:scrollViewDidEndDragging:willDecelerate:)])
	{
		[self.delegate tableViewModel:self scrollViewDidEndDragging:scrollView willDecelerate:decelerate];
	}
}

in my project's code

// .h

@interface Foo : UIViewController <SCTableViewModelDataSource, SCTableViewModelDelegate, EGORefreshTableHeaderDelegate> 
 {
	 UITableView *tableView;
...

	EGORefreshTableHeaderView *refreshHeaderView;
	BOOL isRefreshing;
}

// .m

- (void)viewDidLoad 
{
//...

	if (!refreshHeaderView) {
		EGORefreshTableHeaderView *aRefreshView = [[EGORefreshTableHeaderView alloc] 
												   initWithFrame:CGRectMake(0.0f, 
																			0.0f - self.tableView.bounds.size.height, 
																			self.tableView.bounds.size.width, 
																			self.tableView.bounds.size.height)];
		aRefreshView.delegate = self;
		[self.tableView addSubview:aRefreshView];
		refreshHeaderView = aRefreshView;
		[aRefreshView release];
	}
}

- (void)tableViewModel:(SCTableViewModel *)tableViewModel
   scrollViewDidScroll:(UIScrollView *)scrollView
{
	[refreshHeaderView egoRefreshScrollViewDidScroll:scrollView];
}

- (void)tableViewModel:(SCTableViewModel *)tableViewModel
scrollViewDidEndDragging:(UIScrollView *)scrollView
		willDecelerate:(BOOL)decelerate
{
	[refreshHeaderView egoRefreshScrollViewDidEndDragging:scrollView];
}

#pragma mark -
#pragma mark EGORefreshTableHeaderDelegate

- (void)egoRefreshTableHeaderDidTriggerRefresh:(EGORefreshTableHeaderView*)view 
{
	isRefreshing = YES;
	[self _loadTableData];
}

- (BOOL)egoRefreshTableHeaderDataSourceIsLoading:(EGORefreshTableHeaderView*)view 
{
	return isRefreshing;
}

- (NSDate*)egoRefreshTableHeaderDataSourceLastUpdated:(EGORefreshTableHeaderView*)view
{
	return [NSDate date];
}

- (void)_loadTableData 
{
// ... do something to update
// ... when done:

	if (isRefreshing) {
		isRefreshing = NO;
		[refreshHeaderView refreshLastUpdatedDate];
		[refreshHeaderView egoRefreshScrollViewDataSourceDidFinishedLoading:self.tableView];
	}

// these 2 are still needed to get table to reload (see other thread of mine)
	[tableModel setItems:tableItems];  
	[self.tableView reloadData];	
}



#13 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 01 March 2011 - 11:45 PM

Thanks a lot Brian for posting this in :) I'll be updating the project I attached earlier as soon as the new delegate methods are added. Thanks again!

#14 Matthias Nehlsen

Matthias Nehlsen

    Starting Out

  • STV 3.0 Pro
  • Pip
  • 5 posts
Reputation: 0
Neutral

Posted 21 November 2011 - 12:24 AM

Hi there, are there any updates on this subject? Is the pull-to-refresh now supported? Thanks, Matthias

#15 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 22 November 2011 - 12:30 AM

Hi Matthias,

Yes, the above mentioned delegates have been implemented. Please find attached a working updated sample based on EGOTableViewPullRefresh and STV (please place your own STV files in the "Sensible TableView" folder). Starting STV 3.0, this will be available out-of-the-box and there will be no need for EGOTableViewPullRefresh.

Please tell me if you need any further help.

#16 Matthias Nehlsen

Matthias Nehlsen

    Starting Out

  • STV 3.0 Pro
  • Pip
  • 5 posts
Reputation: 0
Neutral

Posted 22 November 2011 - 01:07 PM

Works like a charm in my app, thank you!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users