Is it possible to access a UITableView's ScrollView In Code From A Nib? - iphone

Right now I am creating a UITableView in a FlipsideView nib. I don't seem to be able to change the background of the table view from within interface builder. I can fix this by creating an outlet and then setting the background. However, I want to give the scroll view rounded corners in order to create a look similar to the iPhone weather/stock app table views. Is there a way to access the scroll view's property in code so that I can set the rounded corners?

A UITableView doesn't have a UIScrollView, it is a UIScrollView. UITableView is a subclass of UIScrollView as can be seen it the documentation. Any properties of functionality of UIScrollView you want to access can be directly accessed via the table view.
Similarly, UITableViewDelegates are all UIScrollViewDelegates.

You can add a corner radius to any view's layer. It would look something like this:
theTableView.layer.cornerRadius = 10.0f; // Or whatever radius you wanted to set
I believe you'll need to link to the QuartzCore framework and import the QuartzCore.h header, too.
This will round the corners of the table similar to how they appear in the flipside of Weather.app.

If I'm not mistaken, the table views for the Stocks and Weather applications are simply single-section grouped table views (UITableViews initialized with the UITableViewStyleGrouped style). You shouldn't need to customize anything about the table view's UIScrollView properties to generate this same rounded-corner effect.

Related

iOS 5 Create a custom view

I was wondering what is the best approach in creating a view such as the one on the left hand side of the following link?
I know how to make apps that use the templates in the storyboard but kind of lost on the guideline when it comes to creating custom views. Does it all get created at runtime using code? Do I need to add one subview per section (Gift, Birthday,...) to my main view? any general approach for creating such a view is appreciated.
At the top level it looks like they have a UIToolbar and a UITableView or a UIScrollView. They have used some custom graphics in the toolbar; possibly they have implemented their own toolbar class.
The table view is probably using a custom UITableViewCell subclass. It is using variable height rows (by defining the tableView:heightForRowAtIndexPath: method in the delegate). They might just be using a scroll view instead of a table view, but I'll assume it's a scroll view for this discussion.
Each cell has appears to have at least three subviews: one to draw the cell's title bar, one to draw the cell's contents, and a UIPageControl to draw the page dots under the contents.
The contents part of the cell looks like it's probably a scroll view, with some subviews to draw images (UIImageView) and labels (UILabel). The subviews of the scroll view are quite different for the different table view cells.
You could lay out an interface like this using nibs. I'd probably use four nibs: one for the top-level with the toolbar and the table view, one nib for the table view cell, one nib for the gift layout (which has a UILabel over a UIImageView), and one nib for the person/date
layout (which has a UIImageView to the left of three UILabels).
You need to set some properties in code. For example, suppose you have one nib for the overall layout of a table view cell. It probably has a view hierarchy like this:
UITableViewCell (or subclass)
UIView to provide the colored stripe across the top
UIImageView for the icon
UILabel for the title (“Browse Gifts”, “Birthdays”, etc.)
UIButton for the disclosure indicator
UIView to provide the white background with shadow
UIScrollView to hold the main content of the cell
UIPageControl
When you load this nib to use for your “Browse Gifts” cell, you need to set the shadow properties of the white background view's layer, because you can't do that in the nib. You need to set the color of the stripe, the icon, and the title text of the cell on the appropriate views. You need to add content to the scroll view (which probably involves loading another nib once for each content item). You need to set the number of pages on the page control.

Adding a subview to UITableCellView

I want to add a subview to the UITableCellView class. However, non of the provided views in the class seem to be able to do exactly what I was looking for.
I basically want to add my own background view, filling the whole cell. However, if I replace the backgroundView, the style from the grouped table view layout isn't displayed anymore. If I add a subview to backgroundView, the subview is not shown at all. If I add a subview to the contentView, I can't draw behind the accessory icon.
What am I missing?
Basically you can't change the backgorund of GroupedTable View.
Try using it with PlainTable.
and add the your backgroung image (of size = cellsize) to cellforRowAtIndex method.
You might want to take a look at this article:
"Easy custom UITableView Drawing"
In particular:
First: the UITableView does not itself
draw anything except the background.
To customize the background of a
UITableView, all you need to do is set
its backgroundColor to [UIColor
clearColor] and you can draw your own
background in a view behind the
UITableView.
Simply add the custom view as part of your contentView. Set a unique reuse identifier for that cell, configure it when you create it and from then on simply reset the data components (this is easiest to do if you create a custom cell controller class so that it can track all the parts and use setters/getters for the data).

Why can't I place a UIActivityIndicatorView on a UITableView by using Interface Builder?

I can place a UIActivityIndicatorView on a UIWindow or a UIView by using Interface Builder like as follows.
(source: hatena.ne.jp)
But I can't place a UIActivityIndicatorView on a UITableView by using Interface Builder.
What's the reason? Are there any ways?
I can place it on a UITableView programmatically.
(source: hatena.ne.jp)
Make the UITableView and the UIActivityIndicatorView both subviews of a parent UIView. You can then place the indicator view atop the table view.
The reason is because UITableView expects to be in charge of all of every one of its subviews for layout purposes. IB doesn't let you put subviews in a UITableView because while it is technically possible it is not supported.
In any case, the activity indicator would scroll up and down with the table, so even if you add it at the right place if the table is scrolled down, you could scroll it off the screen if you're not careful about deactivating user interaction while the indicator is showing.
When I need to show a generic activity indicator on the screen over everything, I use my own version of the UIProgressHUD. The UIProgressHUD is a private internal class, so I don't use that, I just made my own that does the same thing. It makes a view with a black background at 50% opacity and rounded corners, and I add a progress indicator and optionally a label to it, then I just add that view to the main window. Thus, no need for another UIView to encapsulate both, and you're not putting it in the table, which isn't supported (unless you put it within a cell within the table view).

Transparent UITableView on the iPhone?

I've been trying to create a transparent table view recently but I'm not having much luck. The idea is to have a MapView (or anything for an example...) underneath the table view (grouped) where the table cells are solid but the rest of the table view is transparent, showing the map behind.
What I've done so far is create a UITableView and set the background colour to clearColor, however this isn't working too well! Can anyone help?
Thanks
If you put in multiple views in IB you need to make sure you are able to access them by making each one an IBOutlet and hooking them up to the File's Owner.
Then in the ViewDidLoad method for the corresponding view controller, set which views are in the back and which one is in the front by using[self sendSubviewToBack:backgroundView] and [self bringSubviewToFront:foregroundView]. You cannot set in what order the multiple views are displayed in the Interface Builder.

UITableView "autoresize" with custom UINavigationBar size

HTF?
i'm new to the iphone SDK. for a navigationbar and uitable (from the NIB) eg. an empty/new navigation-based app, what is the best way to change the height of the uinavigationbar without it clipping/overlapping the uitableview? i essentially just need to move the uitableview down and i've tried just about everything now.
Q1) is it best to use eg. navigationBar.frame = CGRectMake(0, 20, 320, 88); or should i be using navigationBar.bounds instead?
Q2) do you set tableView.bounds or .frame with CGRectMake? or is there something blatently obvious that i overlooked?
i've tried different autoresizingMask combos too
come on peoples! this should be easy. what am i doing wrong here?
UINavigation has a set size - it's not easy to change, and is likely to violate Apple's HIG if you do change it.
Aside from that, I'm not entirely sure what you're asking. Is the navigation bar obscuring the top of your table view?
If that is the case, simply leave a 44px space above your table view. If that doesn't work, or your table view isn't embedded in another view, you can set the contentInset property on the table view to explicitly make space between the top of the table view's scroll view to the content within the table view.