Adding UITableViewCell Image on button press - ios

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.

Related

UITextField in UITableViewController

I can't find a question like this. I searched all of the Internet but nobody ask this question. Even Apple's tutorials, there is no example. Here is my what I want to do. I want to create an app like Reminders or Wunderlist. I want to emphasize the UITextField of UITableViewCell's first cell as text input.
My first cell is a static cell which is UITextField and the other cell's are the results of UITextField. For example:
Static cell (UITextField)
dynamic cell (Label)
dynamic cell (Label)
...
There is no button for UITextField. I want to get input from keyboard's return like Reminders.app due to I must implement UITextFieldDelegete and equalize in viewDidLoad like textField.delagate = self. The problem starts here. I can connect outlets in UITableViewCell (for UITextField and cells' labels) but in UITableViewCell's instance method, there is no viewDidLoad method and it disallow to use UITextFieldDelagete which can require to get input without using any button. If I use ViewController (not UITableViewController), I can easily connect outlets and use UITextFieldDelegate. How can I solve this problem? Which point I missed?
Please Check Screenshot how to add any Control into UITableViewController
do not forget to change Static cell instead of dynamic prototype in tableView Property.
IBOUTLETs will connects with your ViewController , not with Custom Cell.
How to Set OUTLEts in TableViewController :
ScreenShot
Please feel free to ask

Custom UITableViewCell not Showing Reorder Control

I have a UITableViewCell that is a subclass of CEWendell's SWTableViewCell, a type of cell that allows for custom buttons accessible by horizontal swipe. The problem is that even with tableView:moveRowAtIndexPath:toIndexPath: and tableView:canMoveRowAtIndexPath: implemented, as well as explicitly having [cell setShowsReorderControl:true], the reorder control does not show up when editing begins.
I have also tested this with a regular UITableViewCell with the same result.
This was a somewhat foolish mistake. Since I was using a UIViewController subclass, not a UITableViewController subclass, I needed to set [self.tableView setEditing:!self.tableView.editing animated:true], not [self setEditing:!self.editing animated:true] in order for the tableview to begin editing.

How to access parent object in Objective C

I am creating a Custom UITableViewCell with a UITextfield in it, I would like to know how to access the the custom UItableViewCell from the UITextField delegate didend?
I am trying this
- (void)textFieldDidEndEditing:(UITextField *)textField {
CustomFinishingCell *updateCell = (CustomFinishingCell *)textField.superview;
but that's not returning a UITableViewCell, I think it's returning the UItableScrollView or something like that.
The textField's superview will actually be the cell's contentView. You could probably get the cell by doing:
CustomFinishingCell *updateCell = (CustomFinishingCell *)textField.superview.superview;
That's a little clunky though.
I also wouldn't recommend using tags as that's even more clunky.
What I would do, is create a subclass of UITextField with a property for your CustomFinishingCell and set that when creating the cell (where you add the UITextField). That will ensure everything keeps working, even if the user resorts the cells, adds/removes cells etc, and will work well with cell reuse.
Update:
In a lot of cases, it will be better to actually use #TimReddy's answer and set the delegate of the UITextField to the CustomFinishingCell and move the - (void)textFieldDidEndEditing:(UITextField *)textField etc code to that subclass. That will save you having to create another subclass for UITextField.
You need to have your custom UITableViewCell be that UITextView's delegate. That way you know for certain when the delegate fires it is that UITableViewCell's text view.
You may need to so some cleanup work before the UITableViewCell gets recycled tho.
You could give each cell view a tag, then call UIView's viewWithTag to get the view with the specified tag.
https://developer.apple.com/library/ios/documentation/uikit/reference/uiview_class/uiview/uiview.html
This is how I do it:
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:[textField convertPoint:textField.frame.origin toView:self.tableView]];
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
I prefer this approach because it doesn't rely on tags or maintaining a reference to the container view from the UITextField, or traversing the view hierarchy. All those approaches are brittle for one reason or another.
Tags approach: You need to set the tag in tableView:cellForRowAtIndexPath: and if you have multiple sections, you need to encode the section.
Adding a property to UITextField: This either requires a UITextField category and associated objects, or subclassing UITextField. Both work, but are overkill.
Traversing the view hierarchy is brittle because it depends on implementation details that could change at any time.

Use setHighlighted in the UITableViewController

Do I need to subclass UITableViewCell to use setHighlighted? I am trying to overlay an image on top of my cell between the moment that it is tapped and the moment the action happens. I used to do it by using setHighlighted in a custom UITableViewCell xib but I redid my app using custom cells straight from the sotryboard. It seems like over kill to subclass the whole cell only to be able to use setHighlighted.
Depending on your requirements, you could try using the UITableView delegate methods:
tableView:didHighlightRowAtIndexPath:
tableView:didUnhighlightRowAtIndexPath:
I would guess that subclassing the UITableViewCell and overriding setHighlighted might offer better performance though.

Want to fire IBAction on Touch up Inside of Static TableViewCells

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?

Resources