Display custom button for all cells in UITableView - objective-c

I have a UITableView with a custom cell. On the press of a button called Edit, I want a UIButton checkMarkBox to appear on all cells. So initially checkMarkBox is hidden, but when this IBAction method is called for Edit, I want the checkMarkBox to be unhidden. When I do this now, it only unhides the box for the last cell, not all of them. So I need a way to go through every cell in my table view and unhide the check box. I'm thinking some kind of for loop that goes through all the cells will do the trick, but I'm not sure how to get that started.

When the button is pressed, set a BOOL in an instance variable for your class. In cellForRowAtIndexPath, check that BOOL and show or hide the checkMarkBox. In the IBAction for your button, set the BOOL, and then call:
[self.tableView reloadData];

Related

Show UITableViewCell which can then expand to show more data

I have a UITableViewCell which is currently cluttered and has too much information on the screen at once. I want to make a button, that when pushed, a small view will slide down and show the remaining information, and then when pushed again it will slide back to the original size. I was wondering how I go about doing something like this. I know NOTHING about doing this, so please be specific when pointing me in a certain direction. Thanks!
Do you want single Button for all cells in table view or you want to add button as subview on each cell
1.if you want to add button as subview on each cell
a) Add button with tag value equals to indexPath.row and set target to single method for each button.
ex
-(void)infoButonTapped:(UIButton *)sender;
Now on Click on button find the tag value of button and get the info from the array which you use to populate UITableViewCells.
b) Now create a infoview and add textview on it and set info as text prop of text view and add infoview as subview of view using UIView Animation and hide on next click
you can either use a bool variable in .h file to know hide or show infoView or you can check if infoview has superview then you have to hide infoview else add infoview as subview of self.view.
if you want a common button for all Cell
a) Now on click of button get indexPath for selected cell of tableview using tableview method
- (NSIndexPath *)indexPathForSelectedRow;
this method either return indexpath for selected cell or nil in case no cell selected
Use indexpath for get info from the array and add infoview as subview to view using step 1.b explained above.
you can also get the rect of selected row for setting the cordinate for the info view
by method of tableview
- (CGRect)rectForRowAtIndexPath:(NSIndexPath *)indexPath;
This may help you Show hide table
Or you can use BOOL as a property of cell and hide the subviews of UITableViewCell according to bool also resize frame of cell.
In this case, you better use the following method: -
(void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation{
}
Make a call to above method in your UITableView didselectRowAtIndexPath method.
More explanation is given in below link
UITableViewCell expand and collapse

Make certain UIButtons disappear using UISegmentedControl

I have a set of UIButtons and a UISegmentedControl with 3 segments inside my storyboard.
The segments of UISegmentedControl should work as following;
When first is selected, show all buttons,
When second is selected, hide Button - Button1 and Button - Button2,
(When third is selected, hide Button - Button1, Button - Button2 and Button - Button3).
What should I do to achieve this?
Assign the view controller to be your segmented control's target and implement the action message. You can either do this in IB or using addTarget:action:forControlEvents: and setting the event type to UIControlEventValueChanged.
In the value change action method hide or show the buttons you want using their hidden property.

Can I add a disclosure Button to only one cell in my UITableView?

I have a UITableView and I want to add a disclosure button to a cell but only when the cell is selected.
How can i do it?
Thanks
in tableView:didSelectRowAtIndexPath: save the indexPath to a member variable.
in tableview:cellForRowAtIndexPath: check, if the indexPath is the saved one and set cell.accessoryType
Do it in
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//bla bla bla
}
Remember to have a variable to remove the button from the previous selected cell
In the table view cell set the accessoryType or accessoryView property. You will want to do this in the -tableView:didSelectRowAtIndexPath: delegate method.
Doing it in didSelect means that the disclosureButton only appears after the user releases the selected cell. If you want ti to appear when the cell is highlighted, you need to subclass UITableViewCell and override setSelected: or setHighlighted:
However, the whole point of a disclosureButton is that the button can be pressed and does something different then simply selecting the cell. For that there is the disclosure indicator. The whole premise of making either of these show up only when the cell is highlighted/selected doesn't seem to serve any good UI design purpose in my opinion...but maybe for what you want it does make sense.

UIButton does not work when hidden

I am hiding a UIButton underneath a UITextField. Normally, the UIButton responds just find. However, when I set it to hidden (or when I set alpha to 0), it stops working.
For context, I am including a hidden button under a UITextField because the clickable area to edit the textfield is small--I'd like the user to be able to click anywhere in the neighborhood of the uitextfield in order to make the text field become the first responder. Thus, the code for the button is:
- (IBAction)enterTextField:(id)sender {
[nameTextField becomeFirstResponder];
NSLog(#"Pressed");
}
However, this code does not get called when the button is hidden. Otherwise, it does get called.
Make it a custom button with UIButtonTypeCustom or set the background to clearColor.

How to call an action on double click at a custom NSCell in Cocoa?

i have an NSTableView with custom view cells from NSCell
i'm now trying to get the double click action with this code
[theTableView setDoubleAction:#selector(myDoubleClick:)];
and i have the method set like this:
- (void)myDoubleClick:(id)sender{
NSLog(#"double click");
}
when i double click the cells nothing happens and the nslog is not showing a thing.
maybe it is something with my customs cell.
any suggestions on this?
You Should do this on IB selecting the row and setting the column bindings there's the option co choose a selector from one of your controllers.