UICollectionViewDelegate not firing on UICollectionView subclass with custom UICollectionViewCell and NSObject controller - objective-c

I have subclassed UICollectionView and assigned its delegate and datasource to an NSObject class. I use a custom UICollectionViewCellwith a .xib to construct the collection view's cells. The project can be found here:
https://github.com/JeffModMed/CustomUICollectionView
As you'll see, the datasource methods are working fine, but didSelectItemAtIndexPath and shouldSelectItemAtIndexPath are not called when the user taps on a cell, which leads me to believe there's something with UICollectionViewDelegate. The only other possible problem area I can think of is that there's something wrong with how I'm using the custom UICollectionViewCell class or registering its .xib file.
Note: Please don't answer suggesting that I use UICollectionViewController as an alternative: the code has to be done this way for incorporation with a larger project. Thanks in advance.

In the MMFilterTagCollectionViewCell.xib, select the cell and enable the User Interaction Enabled option.
In the MMFilterTagCollectionView.m file, comment out this line:
#synthesize delegate;

Related

Cannot assign UITableview in xib to custom tableviewcontroller

I know this problem has been tackled quite a lot over there but I stil cannot find a solution in this case.
Basically, I have a tableviewcontroller called "TableViewController" that inherits for some reason from another class called "BaseTableViewController" (which inherits from UITableViewController). Everything works fine when I initialize an instance of TableViewController. I have my tableview in full screen.
Because I added a searchbar (which is working) and needed more room for other elements to be displayed, I want to insert this table view inside a UIView. I created an other UIViewController ("MainView") with a xib file and I added a tableview object as a subview.
My problem is I don't know how I can assign this tableview to my custom class I was using before ("TableViewController"). I tired to import the header file (TableViewController.h) in the header file of MainView.h but it does not seem to solve the problem.
Would anyone have an idea how I could link the tableview inside a UIView to a custom tableviewcontroller?
Thanks!
If it can help, below is my mainview with a tableview object I would like to be linked to my custom tableviewcontroller in order to have it with my datasource, delegate, search bar, etc. I cannot insert "tableViewController" in the custom class.

Touches Began method not called in my custom UISearchBar class

I am adding a UISearchBar which was initialized using a Custom Class to a UIView. And I have overridden the touchesBegan() method.
And I have enabled user interaction in the UISearchBar. But still touchesBegan() method does not fire when clicked on the search bar.
Any Idea why touchesBegan() function is not called?
It'll be great if anyone could help me out.
you have to make sure to set the delegate for UISearchBar. In doing this, in your .h file, type after UIViewController. Then in your nib file, make sure to connect your searchbar to the name of your searchbar found in the Referencing Outlets section. Hope that will help you.
Are you sure you have set the custom class in Interface Builder as UISearchBar?

Objective-C / iOS: Subclassing UITableViewController for a custom view

As we all know, table views in Cocoa Touch are one of the niftiest pieces of framework elements that's out there. As a convenience, Apple gave us a nice view controller class to encapsulate the functionality of a table view in a vc, the UITableViewController.
At the same time, there are times that we want to utilize the functionality of a table view without having it take up the whole screen. However, there seems to be no way to do this by subclassing UITableViewController. Instead, I had to hookup a table view and manually subscribe to the UITableViewDelegate and UITableViewDataSource. If I try to subclass UITableViewController, my app crashes before it can even put the view on-screen...
My question is, is there something I'm missing? When subclassing UITableViewController, I hook up my custom table view to the tableView property in UITableViewController. Is there something else I have to do?
UITableViewController only adds minor conveniences over UIViewController: it creates and positions the table view, hooks up the delegate & datasource (to itself, generally), passes the view controller editing property through to the table, and does a couple of useful UI bits when the view appears. (See [the docs][1] for details.)
Just about all of the above are either A) things that you're needing to change in order to have a non-fullscreen table, or B) things that you can do in a line or two each, and which UITableViewController only does for your convenience. For cases like this, you're better off using your own UIViewController subclass.
Step 1: Subclass UIViewController instead of UITableViewController
MyTableViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>
Step 2: Use interface builder to drop a tableView and custom View
Step 3: Declare the tableView property as IBOutlet in your MyTableViewController header file and bind it to the tableView in the interface builder
IMHO, This process would give you more flexibility.

Using a custom UITableViewController class in Storyboard

In my storyboard, I have created a new UITableViewController object for which I would like to specify some custom code. I created a new controller with the following header:
#interface CustomController : UITableViewController
When I select the UITableViewController in the Storyboard view and navigate to the Identity Inspector, I can see my CustomController in the Custom Class drop-down. However, when I select it, I hear an error sound, which is referred to as "Morse" in the system preferences.
When I deselect the UITableViewController and re-select it, it has cleared my CustomController selection and replaced it with UITableViewController. I do not understand why XCode does not accept this, as from my understanding, this is all that is required to add your own code to a UITableViewController. I am not sure if I have encountered an XCode bug or if I have configured my class incorrectly.
It is possible to use a UIViewController as a UITableViewController, but you have to do some work. If you "convert" a UIViewController to a UITableViewController, you'll need to implement the UITableViewDelegate and UITableViewDatasource protocols. You may also need to provide an outlet for a UITableView. You'll also need to handle keyboard events. Basically a bunch of effort for not much return.
Probably best in your case to start fresh with a new UIViewController class inheritted from UITableViewController.

Mapkit View with tableview together

I am new to Iphone Dev, seems doesn't really understand delegate things. Could we put mapkit view and tableview together in one view?
I searched over, and someone said we can't use more than one delegate in one viewcontroller. As I know mapkit require MKMapViewDelegate and tableview require UITableViewDelegate, am I right till this point?
Then does it mean, we can't put mapkit and tableview in one view together?
The things that make me also confused, I did simple app that use textview and mapkit together. I only pass MKMapViewDelegate to view controller. But textview also require delegate to close the keypad using textFieldShouldReturn. So i manage to link the delegate from IB file, but did't pass UITextFieldDelegate to view controller. And it works.
What is the difference if we link the delegate using IB or pass the delegate param to view controller?
Thanks
A view controller CAN be a delegate for both a map view and a table view. An object becomes a delegate simple by implementing the methods of the delegate protocol, in this case that's MKMapViewDelegate and UITableViewDataSource.
An object can implement any number of protocols. You tell the compiler that instances implement a protocol by adding it to the interface:
#interface MyObject : NSObject <UITableViewDataSource, MKMapViewDelegate>
{
...
There is no significant technical difference between setting a delegate in IB and in code. I would advise setting them in IB because using IB reduces the amount of code you write therefore reducing the possibility of your code failing.