Want to fire IBAction on Touch up Inside of Static TableViewCells - ios

I have a Static TableViewCells on a storyboard. There are just labels in those cells. I would like to fire IBAction event upon touch. What I am doing right now is create a full-size white button and linked to IBAction. But it doesn't show highlighted color when the cell is selected because cell is behind the button.

UITableViewCells have a delegate method specifically for handling row touches -tableView:didSelectRowAtIndexPath:
If you need a custom button over each cell, subclass UITableViewCell instead of going through a storyboard. As much as they may be a timesaver, storyboards are really a limiting factor when it comes to nitty gritty iOS programming.

Try adding this in your cellForRowAtIndexPath (when you initialize each cell):
cell.selectionStyle = UITableViewCellSelectionStyleBlue;
Does this fix it?

Related

Implementing different user interaction function for subviews of a cell

I have a UICollectionView which allows for a user to select a cell and upon doing so view 'A' will appear. I am wondering if it is possible for the subviews of this cell, ex: UIlabel and UIImageView to provide a different functionality for when they alone are selected. For example, if the UIImageView is selected, I want to segue to view 'B' as opposed to 'A'.
I have attempted to implement a UITapGestureRecognizer for both the label and the image, however, the cell's functionality overrules and the resulting view is still 'A'. Any ideas?
Thank you in advance.
What you want to achieve is possible through delegates if you don't have custom cell make a custom cell class then inside custom cell declare your protocol
I assume you have to disable the default behavior of the collection view cells:
cell.selectionStyle = UITableViewCellSelectionStyle.none
However, if you set that and you encounter an overlap issue, please take a look at the 'cancelTouchesInView' property of the 'UITapGestureRecognizer'. Basically, by setting that to false, you allow the children to also receive touch actions.
Furthermore, do not forget each gesture recognizer should have it's own method for you to be able to segue into two different places.

Is possible disable click on accessory View's part of custom UITableViewCell?

I have a custom UITableViewCell in my UITableView of an objective c application. I had a imageView on the left and a label, but now I want add a check in the right position. I have this check added in accessory view into my custom cell, but I have the didSelectRow function too.
How can I disable the didSelectRow in the region of accesoryView?
Is it possible?
You can also make Custom button for your check button. set button click and delegate if you need to perform anything out of your cell class. so when you tap on button you will get button click on that region and if you click on outer space of button you will get did select of tableview.
You can add UIButton on right side with size you want. In your cell create delegate protocol, VC should implement it and set self as delegate.
Though the OP probably has their answer long since, for posterity: this UITableViewDelegate method:
tableView(_:accessoryButtonTappedForRowWith:) exists to resolve this issue/mmet this need.
Cheers!

UICollectionview with IBOutlet-UIButtons not working

I have a two-days-brain-breaking-question to all of you:
I integrated a menu in my application by using a UICollectionView (one line, horizontal scrolling, fixed number of 9 items). Every cell has an own tag and uses an own prototype cell with own identifier. During the cellForItemAtIndexPath I assign a prototype cell to every cell (the prototype cell contains the specific UIButton in the storyboard). If you click a cell (respective the UIButton) a popover should open (this is working quite well, because the popover is anchored to the collection view not to the cell - otherwise Xcode will give an error, because of an outlet bind to repeating content.). Now to the questions:
Dependently from the chosen value in the popover, the name (titleLable.text) of the button should change. I think, an IBOutlet is needed, but not usable, because of the possible (but not happened) multiple (re)use of the cell.
Some other action in the APP could happened randomly, that changes the label of the button. Therefore an IBOutlet is needed too, I think.
I tried to give the prototypes a specific tag, but this (in my opinion) could not be used, because I cannot assign the tags to an UIButton, during loading, because not all of the cells are visible and therefore not reachable in viedDidAppear...
Any help is appreciated. This is a new try for an old problem and the collectionView till yesterday looked quite promising. Any ideas to help? Thanks a lot. I canĀ“t give code, because 90% of the work are done in IB.
you can use NSNotificationCenter to send message from your UIPopoverController to a UICollectionViewCell.
Send and receive messages through NSNotificationCenter in Objective-C?
Just subclass UICollectionViewCell to MyCollectionViewCell and use your subclass in your UICollectionView.
At the -(void)initWithFrame:(CGRect)frame method of MyCollectionViewCell you should subscribe as an observer to NSNotificationCenter, and unsubscribe in dealloc.
Than all your cells may receive notification and react to it.
This is not an optimal way of receiving callbacks, but maybe the simplest.

Adding UITableViewCell Image on button press

Is there a way to add an image to my UITableViewCell when I push a certain button?
According to the documentation, https://developer.apple.com/library/ios/documentation/uikit/reference/UITableViewCell_Class/Reference/Reference.html, a UITableViewCell has a property called imageView which is a UIImageView meaning that all you need to do is create a UIImageView and set the UITableViewCell's imageView property to that of your UIImageView
Yes by creating a subclass of UITableViewCell, you can create tableviewcells in any format you want - Your subclass needs to know if the user pressed the button - many ways to do this - a plist, NSUserdefault or even a property in the TableViewCell subclass
Make sure your TableView delegate methods particularly CellForRowAtIndexpath calls your custom class.
Just [Tableview reloaddata] every time the button is toggled.
A good reference is the Elements sample app from apple.

Custom UITableCellView user interaction

I created a Custom UITableCellView for my application. Each cell has two buttons. The problem I am facing is that the cell itself is selectable which leads to a confused user and poor design. How do I disable the interaction for the cell but keep the interaction enabled for the UIButtons in the cell?
Thanks!
Satyam
You can set the cell.selectionStyle = UITableViewCellSelectionStyleNone; and be sure to keep your didSelectRowAtIndexPath unimplemented. That means that your cells will not be interactive, but you can still get messages from your buttons.
Apart from that, of course I don't know what you're trying to achieve, but remember that you can use a UITableViewCellAccessoryDetailDisclosureButton as an accessory view, which is a different "button" from the cell itself. More info here.

Resources