UITableView delegate methods being called before viewDidLoad - ios

I have a view controller that subclasses UITableViewController. When I push this VC onto the navigation stack, the UITableView delegate methods get called, then viewDidLoad gets called, then the delegate methods get called again. What is going on here?

Because your view is a subclass of UITableViewController, the delegate and datasource are attached from the very first moment it's created, and the methods are called as soon as the datasource is asigned.
Also, you can set a breakpoint on it and see which class called the datasource.

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.

UITableView reloads on show view controller

Please help me to understand why table view reloads on view controller start. I setup outlet for table via storyboard and data source, delegate. I did't call tableView reloadData method.
So When view controller starts '..numberOfRowsInSection' and other table view delegates methods called.
as Apple docs say:
UITableView overrides the layoutSubviews method of UIView so that it
calls reloadData only when you create a new instance of UITableView or
when you assign a new data source. Reloading the table view clears
current state, including the current selection. However, if you
explicitly call reloadData, it clears this state and any subsequent
direct or indirect call to layoutSubviews does not trigger a reload.
https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITableView_Class/
If you really do not need its reloading, create your tableView as a lazy variable and add it to a view programmaticaly when you need it.

How to set Split View Controller Delegate from Storyboard?

I have dragged out a splitViewController, and identified it as a subclass I have created MySplitViewController.
When Right-clicking the splitview storyboard I can see that I've set its Master and Detail view controllers, and furthermore that the delegate is NOT set.
I have made my subclass conform to the protocol and implemented some methods, but they are not being called (which I not understand is because the delegate is not set).
But whenever I try to ctrl+drag from the delegate option in the storyboard to my class, it won't link up. In fact, it won't link up with anything. Am I using this protocol wrong, should my subclass of UISplitViewController not be its own delegate? Then where do I define the delegate in code or otherwise?
Thank you for your time.
Edit: More info-
I tried putting self.delegate = self; in viewDidLoad, but that didn't seem to help.
The particular method I am trying to override is
splitViewControllerPreferredInterfaceOrientationForPresentation:
and I've put an NSLog in the code to notify me if it gets called, which it isn't
As far as I know, NSSplitViewControllers cannot have delegates, and their splitViews can't have their delegates reassigned since the controller acts as the delegate.
If you need access to the delegate methods, simply subclass the controller, then change the class name in Interface Builder.

UICollectionView doesn't call delegate methods

I've setup a UICollectionView in a storyboard and connected the dataSource and delegate outlets. I've registered a cell via nib which I dequeue in the cellForItemAtIndexPath: method.
All works perfectly expect that the delegate methods are never called. For example: When touching on a cell, I expect the didSelectItemAtIndexPath: to be called.
I've double-checked the delegate of the collection view - it's assigned correctly.
Does anybody know the reason why the methods are not called?
It's completely my fault. I've added a transparent subview to the front which consumes the touches - a really bad mistake.

Trying to adding a UITableView into a view hierchary with it's own view controller

I have a view hierarchy that has a UIViewController as Files Owner in the XIB.
I need to add a UITableView into the hierarchy that has it's own controller (a UITableViewController subclass) because I am implementing a pull-to-refresh UI using http://github.com/leah/PullToRefresh
What I did:
created the new UITableViewController subclass, BuddyTableViewController
implemented the datasource & delegate methods
added the UITableView into the hierarchy in Interface Builder
dropped an NSObject into the XIB and set the class to BuddyTableViewController
set the delegate & datasource of the tableview to BuddyTableViewController and hooked the UITableView to the tableView property of BuddyTableViewController
When the view displays it crashes immediately.
When running in debug with NSZombieEnable=YES reveals the message:
*** -[BuddyTableViewController numberOfSectionsInTableView:]: message sent to deallocated instance 0x69551d0
numberOfSectionsInTableView only contains return 1;
I don't understand why BuddyTableViewController is being deallocated.
You need to hook it up to an outlet in the owner, having it as delegate and data source is not enough because neither of those retains it. If the object is not retained by you it will be autoreleased.

Resources