Adding a UIActivityIndicatorView to a UITableViewController - iphone

How is a UIActivityIndicatorView added to a UITableViewController?
I have tried adding it in Interface Builder and when I drag and drop it onto the view, it just disappears.
I need to show the activityIndicator while the table loads in its data.

If you put a tableview (not a tableview controller) inside another view you can place the activity indicator on top of it. To clarify:
- Plain xib file with a Files Owner and a First Responder
- Add a View (not a view controller)
- Add a TableView into the View
- Add an Activity Indicator into the View
For some reason, the various view controller objects don't like you adding things to them and the tableview object doesn't like you adding things to it. I'm sure that the docs make this really clear somewhere.

You can add UIActivityIndicatorView to your tables in the Interface Builder (IB), but a recommended way would be:
User IB to create and customize a UITableViewCell. Put a UIActivityIndicatorView inside this cell.
Programmatically load your table cells with the customized UITableViewCell nib file.
Programmatically hook up IBOutlets of such UIActivityIndicatorView.

Related

CollectionView in Nib doesn't have cells?

I'm building my app like that: one ViewController = one nib file etc.
But when I added collection view in my view controller for some reason I can't add cells to it, what is the problem?
Also when I drag the cell to this collection view nothing happens...
Same problem with TableView...
Nibs don't support adding cells to collection views or table views directly in the nib. Only storyboards do. To use a nib with a collection/table view in it, you would have to programmatically register your cell class (or cell nib) with the collection/table view.

UITableViewController and sub views

I have a screen where I want to display the details of some product. I'm using storyboards.
I have done this using a tableview with static cells, but static cells can only be done within a tableview of UITableViewController. And the problematic point is that I also want to have a Imageview within this controller. this is not possible as the tableview of a UITableViewController take all the screen size.
So I'm doing the Imageview as a subview of the tableview.
I'm wondering if it is the right way to do it, there are similar issues on stackoverflow but none is corresponding to my use case (storyboard + tableviewcontroller + staticcell + sub view)
Without writing any custom code, you could either:
Put a UIImageView in the table view's header or footer view.
Create a static cell and put the UIImageView in that. Table cells don't have to be uniform length, you could make it taller than the other cells if needed.
You can have your subclass of UITableViewController. After you initialize it take its view (tableView) and add it as subview to some other view controller. This way you can set the frame of tableView to occupy the bottom of the (top containing) view controller. To the same view controller you can add additional subviews like UIImageView and position it on the top. The only problems you will encounter might be related to missing notifications to your UITableViewController subclass (viewWillDisappear, viewDidDissappear, viewWillAppear, viewDidAppear, ...). But you can forward them to from your top view controller. Or you could use methods from iOS 5 to add subclass of UITableViewController as a child view controller and position it as you wish. But this is useful if you plan on supporting devices with iOS 5.0+.
See documentation of method in UIViewController:
- (void)addChildViewController:(UIViewController *)childController __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_5_0);
Use a UITableView as a property of the viewController and add it to vc.view, rather than subclass a UITableViewController, then set its frame as you like
Add the imageView to vc. If you need to put it on top of the UITableView, for example, add it as the TableView's header.

How do I add a Navigation Bar to a UITableViewController in Interface Builder?

Interface builder does not let me click and drag a Navigation Bar onto a Table View Controller!!! It is super frustrating.
All I want is a table view with an edit button (done in interface-builder). If this is not possible, then how do I add a navbar progammatically?
From the outline view, make sure your Table View Controller is selected.
Then go to the Editor menu, and click on the Embed In submenu, and choose Navigation Controller and voila. You have your navigation controller pointing to your tableview controller with a relationship built in.
For a table view with an edit button at the top, use a UINavigationController, with a UITableView as the rootView. That means you're going to make a custom UITableView subclass for your table view, and use that as the rootView of your UINavigationController instance. (Programatically, it's set with UINavigationController's -(id)initWithRootViewController. It's also settable through IB.)
Then, in your UITableView subclass, uncomment the following line:
- (void)viewDidLoad {
[super viewDidLoad];
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
and voilà, your UINavigationController's view shows up as a table view with an edit button on the right side of the navigation bar.
Since the controller is at the top of the stack, there's no "back" button on the left, so you can use self.navigationItem.leftBarButtonItem for whatever UIBarButtonItem you create.
I agree that it's difficult to figure out how to do things like this in Interface Builder, but luckily it is possible to add a Navigation Bar and Bar Button Item to a Table View this way. Here's how to do it:
Drag a blank View (an instance of UIView) from the Library to the area near the top of the Table View. As you drag near the target area, Interface Builder will highlight it in blue to show you where to drop the View. Let go, and the View will be added as a subview of the Table View's header view.
Drag a Navigation Bar from the Library and drop it on the blank View you just added.
Drag a Bar Button Item from the Library and drop it onto the Navigation Bar.
EDIT
The problem with the above approach is that, as Bogatyr points out, the Navigation Bar will then scroll along with the Table View. Apple recommends using a custom subclass of UIViewController that owns both the Navigation Bar and an instance of UITableView resized to fit. Unfortunately, that means you would have to implement the UITableViewController behavior needed by your UIViewController subclass yourself.
Another approach that seems to work well is to create a custom subclass of UIViewController that owns a blank background view containing the Navigation Bar as well as a blank content view (an instance of UIView) that fits under the Navigation Bar. Your custom subclass would have an outlet pointing to an instance of UITableViewController in the same nib file.
This has the advantage of allowing all the view components to be created and configured in Interface Builder, and doesn't require implementing UITableViewController methods from scratch. The only detail you'd need to take care of in the Table View Controller's parent would be to add Table View as a subview of the parent's content view in viewDidLoad.
The parent could implement the action methods for the Navigation Bar's button items, and implement the delegate pattern if necessary.
From iOS6 onwards, you can use container view. So what you have to do is take View controller, add the navigation bar to it, then add a Container View to same view controller. It will automatically, add the new view controller link to your container view. Now simply delete that, and your table view controller in the story board. Now embed the table view controller to container view by control drag. Hope it helps.
First add a navigation controller and put the table view controller (as root view controller) onto the navigation controller. This is how it is done in Code because I don't use IB.
Why in the world you can't drag a navigationItem into a .xib file with File's Owner set to a subclass of UIViewController and hook the navigationItem up to the UIViewController's navigationItem outlet is beyond me. It seems like a real hole in IB / XCode integration. Because you can certainly drag an instance of ViewController to a xib file, and drag a navigationItem into the ViewController, and then set the title and barbuttonitems that way.
So if you want to define your UITableViewController subclass object's navigation bar in IB, you have to create your TableVC object in a xib file (not the one .xib file that contains the tableview for your UITableViewController, though!). You then either hook the TableVC object up to be an outlet of another object (like your application delegate), which works if you need just one instance of your TVC throughout the lifetime of your app, or if you want to dynamically create instances of your TableVC in code you load this extra .xib file manually via loadNibNamed:owner:options method of the NSBundle class.
These steps worked for me in iOS 9:
Add a View Controller to the Storyboard. Make UITableViewController as base Class.
Add a Navigation Bar object onto view controller at the top.
Add a Table View below Navigation bar.
Add a Table View Cell into Table View.
Add constraints.
This is the other easy way ;
Choose your TableViewController screen on storyboard.
Click Size Inspector symbol on the right menu and find Simulated Size
Change Fixed to Free Form
You can add navigation bar easily.

change tableview to view in iphone

i'm having a tableview nib file.(contains a list)
i want to add some buttons with it
so i want to change the tableview to view and put the tableview inside that view
then add buttons to the view..
what to change in the class files and how to do this?
if you want to change the tableview to view, you can do in the IBOutlet.
By changing the value in the Inspector Identity from UITableView to view. So that it will change to view and you can add buttons and some to that view.
or else you can add the buttons with out changing the IBOutlet with code.
you can change the UITableView frame and you can add buttons to the view.
Regards,
Satya

Custom iPhone App Tab Bar

Alright, this seems simple enough but I haven't found much documentation or posts regarding this. Basically, I want to have a completely custom tab bar at the bottom of my app. Being new to iPhone dev I thought I could do the following:
Place custom images on bottom of
screen to act as tab buttons.
Create a UIView (lets call it
"ContentView") to fill the rest of
the screen that will display the
appropriate tab's NIB. This
"ContentView" is inside the main
UIView for the NIB.
Hook up image "press" actions to the
controller managing all this.
I'm not sure how I would go about loading the appropriate NIB into the "ContentView" with this method though. From the "Touch Up" action method in the controller can I dynamically load a NIB into that "ContentView" UIView?
Something about this whole thing makes me uneasy.
Is there a better way?
To solve your problem I would create a nib with a UIView and its associated content in it. Connect the nib to a UIViewController. This will be the content of each tab. Create as many of these UIView-UIViewController combination as needed.
When the user touches a tab, create and load the UIViewController from the nib using
– initWithNibName:bundle:
Add the UIView in the nib to the main content view as a subview. Use
– addSubview:
As the user presses other tabs load the other nibs into memory and add their UIView into the main content view as a subview.
If a view is already in memory you can show and hide subviews with the following methods.
– bringSubviewToFront:
– sendSubviewToBack:
I think that would work.
You can solve this by,
either make different views with same tab bar image and custom button(load view on IBAction for button click:toucp up inside) or you can make different views for the same view(so you can hide views and show only one view at a time accordingly).
and you can load view (if you app is view based then add other views on window otherwise for navigation based app you need to pushViewController of navigation controller.
This is a tricky task but you need to handle this.