1

So I read here that I can simply drag a UITableViewCell to the bottom of my UITableViewController in storyboard and have it act like a footer. This footer row has an activity indicator in it that's it. It's width is 320 and height 55 with the indicator centered in the row. Note that it's a UIView rather than a UITableViewCell because I can only get it to work with the former.

First, The UITableView doesn't stop at the footer. One can see the footer if he extends his scrolling beyond the bottom of the UITableView. As soon as the user releases his finger, the footer disappears from site as the UITableView returns its scrolling back to the last element. I am trying to do what Instagram is doing - if you scroll to the bottom you can see their custom activity indicator at the bottom and the UITable will remain its scrolling position at that indicator. How can I achieve this?

Second, I have some custom scrolling performed by certain user actions. Right now, I have the following code:

    if (row + 1 < [self.tableView numberOfRowsInSection:0]) { 
        [self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForItem:row+1 inSection:0]
                              atScrollPosition:UITableViewScrollPositionMiddle animated:YES];
    } else {
        // TODO scroll a little down so the user can see the activityIndicator
    }

How can I tell my tableView to scroll programmatically to the footer and have it stop there?

Third During the very beginning, my UITableView has to fetch things from my server before it can populate the tableView. Unfortunately i can't get the footer view to maximize the space of the UITableView so that the activityIndicator will appear in the center. Right now this is how it looks:

enter image description here

I think I have the structs set correctly:

enter image description here

I suspect that having a UIView within a UITableView might prevent the view from maximizing.

Summary Any recommendations on the above issues? I apologize for the length of this question, but I feel that they are all related to the same problem mentioned above.

Community
  • 1
  • 1
xjq233p_1
  • 7,810
  • 11
  • 61
  • 107
  • First of all the UITableView header and footer can accept any UIView or subclasses of it. So adding a UIView, is perfectly fine. Second, what you are describing with the footer, doesn't make sense. The footer is always the last element in the UITableView. Show us your code for the UITableView datasource and delegate methods. Third, I don't know why you want to use the footer view as a loading indicator, instead of a UIView, that will overlay over the UITableView, but in this case, just disable the vertical autosizing of the Activity indicator, and remove the top and bottom align setting. – Lefteris Mar 28 '13 at 11:29
  • stupid question maybe, in what ways does this behavior differ from setting the `tableFooterView` property? – Carl Veazey Mar 29 '13 at 05:33

3 Answers3

1

I finally figured it out.

With regards to @zing and @Lithu answers, that worked. However, returning a footerView from this method forces the footerView to "stick" to the bottom of the TableView. By this I mean that the footerview will always be shown (which is not something I want)

I finally used self.tableView.footerView = MyView. I disabled ALL the spring and struct settings on my UIView and it fits perfectly. (I've previously set it to maximize hoping to have it maximize when there is nothing in the table)

Regarding centering the activity indicator: I ended up setting the footer view to hidden if there's nothing in the UITableView (by checking in numberOfRows). I programmatically added the ActivityIndicator in the center if this occurs.

Thanks for all the answers!!

xjq233p_1
  • 7,810
  • 11
  • 61
  • 107
0

Did you try to do it in the proper delegate for UITableview Footer

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
Lithu T.V
  • 19,955
  • 12
  • 56
  • 101
0

Use This code to add any view in the footer. e.g.

- (UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
       UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 50, self.tblView.frame.size.width, 49)];
       return footerView;
    }
iCoder
  • 1,298
  • 1
  • 9
  • 25
  • What if you have UIActivityIndicator in the center (or something else) and user rotates the device to Landscape orientation? If you have a bunch of items inside, youll need to manually align them all or write autolayout code, right? – Martin Berger Oct 03 '13 at 13:50