Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Google Sign In with OpenID

Best Practices for UITableView within UIView within UIScrollView

acjrocksacjrocks Posts: 18Registered Users
edited November 2009 in iPhone SDK Development
Here is my set up.

I have a UITableView within a UIView, which is within a UIScrollView. I got a UIViewController as my controller to manage all these items.

My UIView has a UIImage, a UILabel, and the UITableView within it. Everything here is working just fine, down to the loading of data on the UITableView for the most part. As mentioned, the UIView is within a UIScrollView, which I have done so that I can scroll the UIView up and down.

I got it scrolling just fine, but I've run into a couple of issues that I can't seem to find answer to. Can someone chime in here and give me their input on the below items?

- When I scroll the UIView, it scrolls the whole view as it should, but the UIViewTableCells are not loading up when they come into view. On a normal UITableView set up, when you scroll, as each cell becomes visible, that cell is populated with data. With my set up, it scrolls the whole view, but you can see the UITableView being cut off at the bottom when the view scrolls. How can I remedy this problem?

- If I start my scroll on the UITableView, it scrolls the UITableView only, and not the whole view. I don't want it to scroll the table view at all. I want it to scroll the view. Is this as simple as catching an event on UITableView, canceling it, and letting the UIScrollView object handle it?

Any help on this would be appreciated. Thanks guys!
Post edited by acjrocks on

Replies

  • acjrocksacjrocks Posts: 18Registered Users
    edited May 2009
    Any help? Or maybe just a link that'll show me how to do?
  • jsdjsd Posts: 900Registered Users
    edited May 2009
    acjrocks wrote: »
    Any help? Or maybe just a link that'll show me how to do?

    I haven't had any luck with UIScrollViews and scrolling stuff off the screen and back. It just seems to disappear. The best I can offer is that when the scrolling stops you force an update of the affected part.

    Something like:
    - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
    {
    	[myTableView reloadData];
    }
    

    It's gross but it works for me. (Although the user sees a blank space until they stop scrolling, then the missing stuff 'pops' in.)
  • acjrocksacjrocks Posts: 18Registered Users
    edited May 2009
    jsd wrote: »
    I haven't had any luck with UIScrollViews and scrolling stuff off the screen and back. It just seems to disappear. The best I can offer is that when the scrolling stops you force an update of the affected part.

    Something like:
    - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
    {
    	[myTableView reloadData];
    }
    

    It's gross but it works for me. (Although the user sees a blank space until they stop scrolling, then the missing stuff 'pops' in.)


    Yeah. I was hoping to avoid this because it really doesn't look good if the TableView is broken off, but then the missing cells show up after scrolling stops. But thanks though!

    I'm surprised there aren't more tutorials for something like this. I've seen many programs that have at least one nib with these controls on them. I've found some open source iphone programs out there that do this, but considering I'm new to iPhone programming, I'm finding it hard narrowing down how it's done. I need someone to explain it.
  • jsdjsd Posts: 900Registered Users
    edited May 2009
    acjrocks wrote: »
    Yeah. I was hoping to avoid this because it really doesn't look good if the TableView is broken off, but then the missing cells show up after scrolling stops. But thanks though!

    I'm surprised there aren't more tutorials for something like this. I've seen many programs that have at least one nib with these controls on them. I've found some open source iphone programs out there that do this, but considering I'm new to iPhone programming, I'm finding it hard narrowing down how it's done. I need someone to explain it.

    Get the "Beginning iPhone Development" book by Dave Mark & Jeff LaMarche. It's a great resource.
  • acjrocksacjrocks Posts: 18Registered Users
    edited May 2009
    I made some progress a bit ago. Keep in mind I'm still a beginner with iPhone Programming. Coming from .NET development. :D

    I resized the UIScrollView to a larger height, which is the superview, and now when I scroll, I get more cells. But the logs show it is loading all the extra cells when the view is first shown, which isn't good. Not that I will have a lot of cells to show, but in the case that I do, it should load them as they come into view, instead of loading them all up front.

    And on top of this, it looks like I still have the same issue. Yes, I get more cells scrolling down now, but this seems to be only cause I increased the height of the view and superview. When I get to the end of view, you can see where the cells are cut off. Bummer. I thought I had something.
  • acjrocksacjrocks Posts: 18Registered Users
    edited May 2009
    Here is a screenshot of what I'm looking to do. This looks like a UIView and label up top, and a UITableView below it. When you scroll, it scrolls the whole view including the table view.

    Is it possible that top area with the ImageView is just a custom cell?

    dev.tif
  • jsdjsd Posts: 900Registered Users
    edited May 2009
    acjrocks wrote: »
    Here is a screenshot of what I'm looking to do. This looks like a UIView and label up top, and a UITableView below it. When you scroll, it scrolls the whole view including the table view.

    Is it possible that top area with the ImageView is just a custom cell?

    dev.tif

    yeah, you could certainly do that with a custom cell. in fact, thanks for the idea - i'm going to steal it :)
  • brendandbrendand Posts: 223Registered Users
    edited May 2009
    Just make your top area the tableHeaderView of the UITableView.

    Like this:

    myTableView.tableHeaderView = myHeaderView;

    Where myHeaderView is the view you have with the image, label, and buttons.

    That's exactly what the header view is designed for. There's also a tableFooterView if you want to put something below all your rows.

    Hope that helps!
  • acjrocksacjrocks Posts: 18Registered Users
    edited May 2009
    brendand wrote: »
    Just make your top area the tableHeaderView of the UITableView.

    Like this:

    myTableView.tableHeaderView = myHeaderView;

    Where myHeaderView is the view you have with the image, label, and buttons.

    That's exactly what the header view is designed for. There's also a tableFooterView if you want to put something below all your rows.

    Hope that helps!


    Whoa! I think that might be it. I had no idea there was a tableHeaderView option. The hardest looking things always tend to have the easiest answers.

    Hey thanks! TapForms huh? Great job on that. Absolutely love that app!
  • brendandbrendand Posts: 223Registered Users
    edited May 2009
    acjrocks wrote: »
    Whoa! I think that might be it. I had no idea there was a tableHeaderView option. The hardest looking things always tend to have the easiest answers.

    Hey thanks! TapForms huh? Great job on that. Absolutely love that app!

    Thanks! The next update is going to Apple this week. Hope you like it too. Gotta post some screenshots now.
  • shiva.0537shiva.0537 Posts: 54Registered Users
    edited November 2009
    Hi,

    I am also trying to put table view in a scroll view, i am able to update table view properly, when new page is scrolled, but not able to get table view vertical scroll.
    please help me.
Sign In or Register to comment.