IOS SplitView TableViewController query - ios

I have one SplitViewController with default settings added into an xib file. Its Table View controller i defined as another class (in Identity Inspector) as a TableView Controller class I created.
Now I have put some code in its
...numberOfRowsInSection:(NSInteger) section
and ...cellForRowAtIndexPath:(NSIndexPath *) indexPath
It works fine with total values in its table according to numberOfRows I have defined and elements in cell according to what cells I create and return in the appropriate method.
My question is:
How is table coming into the SplitView because when I customize UITableView in the xib of my TableViewController, its changes do not appear in the SplitView's left section. (I guess that table View is non-customizable? )
Secondly How does iOS initialize that TableViewController class from XIB because I have to put some initialization code that when that TableView is created, do following things. I tried over-riding various init functions it does not call any of those. How can I initialize some data when that TableViewController is initialized?
Thanks.

The table view is customized in the XIB that contains the split view and not in an own XIB file
You can do 2 things: override initWithCoder: (remember to use the self=[super initWithCoder: pattern) or override - (void)awakeFromNib

Related

Table View's Delegate Method Cell for row at not called

I am using a table view and set the delegate and datasource in view will appear.
return 1 in number of section and 5 in number of rows but cell for row at delegate method is not called. I checked my storyboard view cell's ideantifier and class name is correct. Pls help
There are few things that may be or are wrong with your code. First one is that you should setup the delegate in storyboard or ViewDidLoad (in storyboard drag from tableView to the ViewController instance and select both - delegate and datasource) The other thing is that you may made a typo when writing the code for delegate methods(always use automatic method completion feature in xcode)
After setting delegate and datasource , reload the table view.

Where is the place to programmatically adjust the view of a UICollectionViewCell?

I would like to programmatically apply some view modifications once a UICollectionViewCell has been created and all its view outlet are being assigned (right as a UIViewController's viewDidLoad method). However I don't want the code to be re-run when the cell is being reused as this view initialization/modifications have to be done only once. Is there a method that I should override in my custom UICollectionViewCell implementation that is being called as soon as the view outlets are assigned?
There is the applyLayoutAttributes: methods that is just called after the view is added to the collection view. However from its name and its description it doesn't sound to be the right place to initialize the view. In addition this method might be called for every re-use as well. However using an initialized-flag this could be worked around.
If it's being loaded from a storyboard or nib then you can do that in.
- (void)awakeFromNib
If it's in code then there is an init method something like initWithFrame:reuseIdentifier.
Somrthing like that anyway.
These are both run once when the cell is first loaded.

iOS Simulator doesn't show prototype cell

I'm currently learning Objective-C by doing tutorials ("the iOS Apprecente")
Now I need to make a checklist
I added in viewController.h
#interface ViewController : UITableViewController
Normal there stands
#interface ViewController : UIViewController
The next is to go to Storyboard place there a TableViewController, give it the name: ChecklistsViewController (Identity inspector > Custom class > class.
I added a label into the first Table view cell. But when I run it there's nothing.
What to do?
Two separate issues here:
The choice of UIViewController with your own IBOutlet for the table view or a UITableViewController is simply a question of whether, in Interface Builder (IB), you added a standard view controller to which you added a table view, or whether you used a table view controller. You use the former if you have other controls on the view in addition to the table view. You'd generally use the latter if the table view is the only thing being presented in that view controller's view. Bottom line, your choice of UIViewController or UITableViewController is dictated by how you added the scene in IB. From your description, it sounds like you went down the UITableViewController approach, which is fine.
In terms of why you're not seeing anything, there are a bunch of possible reasons:
Did you specify the cell identifier for your table view cell prototype? Is it the same identifier you're using in cellForRowAtIndexPath method?
If you manually added a table view to a standard view controller's view, did you specify the view controller as the delegate and dataSource for the table view? Also, did you create an IBOutlet for the table view itself, hooking that up in IB? (If you used a table view controller in Interface Builder, you don't have to do these steps.)
You might want to double-check that the base class for the table view controller was correctly set in IB.
Did you implement all of the UITableViewDataSource methods, notably numberOfRowsInSection? If you don't do that, it will conclude that there are no rows, and no cells will be generated.
You say that you specified the base class for your view controller in IB to be ChecklistsViewController. But in your code snippets, it looks like you're using a custom class called ViewController. Make sure you're using the same UITableViewController subclass for both.

Table View Controller code not getting invoked

I've got an app with a Web View and a Table View. The Web View works fine, but the Table View does not seem to be invoking the TableViewController.h code when displaying. I think I missed a linking step somewhere, but I can't seem to figure it out.
To clarify, I originally set up the project as a single view application but later added a Navigation controller and the Table View manually.
After I manually added the Table View to the storyboard, I created TableViewController.h and TableViewController.m, but I can't figure out how to link the code to the Table View in the story board.
Can someone explain what I'm missing?
Set the class of the controller you're using in the storyboard to be TableViewController
Two scenarios:
First, if you added a tableview to a standard UIViewController (i.e. you dragged a table view to your blank, standard view controller in Interface Builder and the .h for your view controller specifies that it is a subclass of UIViewController), then you have to specify the "data source" and "delegate" properties of your table view manually. Thus, you should make sure to configure the "data source" and "delegate" for your tableview to reference your view controller. You can do this in either Interface Builder (by selecting the tableview, going to the "Connections Inspector" in the far right panel, and then make sure you've specified the outlets for data source and delegate):
Or set dataSource and delegate properties in your UIViewController subclass viewDidLoad code:
self.tableView.dataSource = self;
self.tableView.delegate = self;
In this scenario, you also want to ensure that you created a IBOutlet for your tableview, too.
Alternatively, if you used a UITableViewController (i.e. you removed the blank view controller and added your own table view controller into your storyboard in Interface Builder and have made sure that your view controller is a subclass of UITableViewController, not UIViewController), see Moxy's answer.

Displaying a UITableView from a nib file is not the same as creating it programmatically

I'm facing an issue using a UITableViewController from a nib file. As a workaround I'm creating it programmatically and it's fine but still the behavior struggles me... Let me explain the issue.
Nib file
I have a Table.xib file that contains only a UITableView which is attached to the file owner's view member (as well as the delegate and dataSource outlets). The file owner is of type MyTableViewController (which extends UITableViewController). The UITableView is defined as grouped style and everything else is default settings
UITableViewController
Nothing fancy here, I set that the view must contain one section and one cell in the section. A default cell is returned. (source here: http://pastebin.com/FuEK71Cr)
AppDelegate
I want to display the table directly after launching and my issue raises when I load the controller using:
UITableViewController *startCtrl = [[MyTableController alloc] initWithNibName:#"Table" bundle:nil];
Doing so will display the table but the top of it is above the top of the screen. In other words I have to scroll upwards to see the top of the table, sounds like a wtf to me :)
Instead if I init the controller programmatically and set the UITableView in grouped style it's working fine:
UITableViewController *startCtrl = [[MyTableController alloc] initWithStyle:UITableViewStyleGrouped];
What am I missing?

Resources