Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add support for custom frame #37

Closed
wants to merge 1 commit into from

2 participants

@XiaonuoGantan

Add a method -(id)initWithFrame:InScrollView: in ODRefreshControl to
allow users of the class to provide a custom frame. Currently,
ODRefreshControl is assuming that the parent UITableView has vertical
UITableViewCells, which may not be the case in apps like Pulse-news,
where the UITableViewCells are layed out horizontally on the
UITableView. Add the aforementioned method to allow assigning custom
frame for the control so that it can animate properly in a horizontal
UITableView.

@XiaonuoGantan XiaonuoGantan Add support for custom frame
Add a method -(id)initWithFrame:InScrollView: in ODRefreshControl to
allow users of the class to provide a custom frame. Currently,
ODRefreshControl is assuming that the parent UITableView has vertical
UITableViewCells, which may not be the case in apps like Pulse-news,
where the UITableViewCells are layed out horizontally on the
UITableView. Add the aforementioned method to allow assigning custom
frame for the control so that it can animate properly in a horizontal
UITableView.
46f3844
@Sephiroth87
Owner

Mhm, first of all, there's something very wrong, you should not use self before init...

Secondly, I don't see the point of this.
I checked pulse, but it's a simple tableView and the control will work perfectly.
Can you send me an example project where this is needed?

@XiaonuoGantan

It's incorrect to use self before init. The method - (id)initInScrollView:activityIndicatorView: should be refactored into another method which calls another internal initializer to return self. That internal initializer should also be called by - (id)initWithFrame:InScrollView: to provide a custom frame.

An example project where this is needed is https://github.com/XiaonuoGantan/Felipe-Laso-HorizontalTableView-Demo-With-ODRefreshControl. Notice the file HorizontalTableCell_iPhone.m includes two ways to initialize a ODRefreshControl and the control cannot display properly when a custom frame is not provided.

@Sephiroth87
Owner

I now understand what you're trying to do, but it's such a special case that I don't like have to handle it here...
(Also, that surely is an awkward way to implement an horizontal table, IMHO)...

Anyway, there's a much more simple solution to the problem: simply instantiate the refreshControl BEFORE applying the transform to the table view, and it'll work automagically ;)

@XiaonuoGantan

You're absolutely correct! How come I never thought about this simple solution?!

Thank you for correcting my horrible code :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 5, 2012
  1. @XiaonuoGantan

    Add support for custom frame

    XiaonuoGantan authored
    Add a method -(id)initWithFrame:InScrollView: in ODRefreshControl to
    allow users of the class to provide a custom frame. Currently,
    ODRefreshControl is assuming that the parent UITableView has vertical
    UITableViewCells, which may not be the case in apps like Pulse-news,
    where the UITableViewCells are layed out horizontally on the
    UITableView. Add the aforementioned method to allow assigning custom
    frame for the control so that it can animate properly in a horizontal
    UITableView.
This page is out of date. Refresh to see the latest.
View
3  ODRefreshControl/ODRefreshControl.h
@@ -30,6 +30,9 @@
- (id)initInScrollView:(UIScrollView *)scrollView;
+// use custom frame
+- (id)initWithFrame:(CGRect)frame InScrollView:(UIScrollView *)scrollView;
+
// use custom activity indicator
- (id)initInScrollView:(UIScrollView *)scrollView activityIndicatorView:(UIView *)activity;
View
11 ODRefreshControl/ODRefreshControl.m
@@ -51,9 +51,18 @@ - (id)initInScrollView:(UIScrollView *)scrollView {
return [self initInScrollView:scrollView activityIndicatorView:nil];
}
+- (id)initWithFrame:(CGRect)frame InScrollView:(UIScrollView *)scrollView {
+ self = [super initWithFrame:frame];
+ return [self initInScrollView:scrollView activityIndicatorView:nil];
+}
+
- (id)initInScrollView:(UIScrollView *)scrollView activityIndicatorView:(UIView *)activity
{
- self = [super initWithFrame:CGRectMake(0, -(kTotalViewHeight + scrollView.contentInset.top), scrollView.frame.size.width, kTotalViewHeight)];
+ if (CGRectEqualToRect(self.frame, CGRectZero)) {
+ CGRect sRect = CGRectMake(0, -(kTotalViewHeight + scrollView.contentInset.top),
+ scrollView.frame.size.width, kTotalViewHeight);
+ self = [super initWithFrame:sRect];
+ }
if (self) {
self.scrollView = scrollView;
Something went wrong with that request. Please try again.