UITableView inside UITableViewCell - ios

I have the UITableView(tableA) with custom cells(cellA). Inside of each cell I have some views and UITableView(tableB) with Custom cells(cellB). There is a button in each cellB. I need to handle the TouchUpInside action from this buttons, but when user taps outside buttons I need to animate cellA selection and call method -(void)didSelectRowAtIndexPath from tableA delegate. In other words, user should select cellA then he taps outside button, tableB should miss this action for tableA. How can I do this?
I tried to set userInteractionEnabled property to false for tableB and cellB, but in this case buttons became disabled.

In the delegate of tableB, implement didSelectRowForIndexPath to make table A select the current row. The row will only receive the action if the touch wasn't on the button.
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableA selectRowAtIndexPath:indexPathThatContainsTableB];
}
You may need to call the delegate method for tableA's delegate yourself.

Related

How can I determine when a UITableViewCell's action buttons are shown and hidden?

Is there a delegate method or something that I can implement that allows me to do something when action buttons of my tableview cell is shown and hidden again?
You can set some bool property at tableviewcell level, which could work like the trigger point to understand, whether the more option actions are visible or not.
You can also validate them with content offset of tableviewcell contentview, if offset < 0, it means the more option action buttons are visible, else are not visible.
The tableview delegate methods:
-(void)tableView:(UITableView *)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath
and
-(void)tableView:(UITableView *)tableView didEndEditingRowAtIndexPath:(NSIndexPath *)indexPath does the trick.

Select row when cell in tableview is a tableview iPhone

In my app, I am using tableview and cell in this which is tableview too. All things work good but when I want to handler selected cell on tableview which is a cell but i don't control
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
}
This function call at tableview parent only. But in my case, i want to call this function in both of tableview (parent tableview and tableview in cell).
Thanks!
Did you imported UITableViewDelegate? and add it to you table view as self.tableView.delegate = self,Better to check once!
Inside the table view of the cell, please set the delegate and datasource as the cell views reference.
As I think, your parent tableView get the select action and block the child table view from receive this action. I think there're two or more approaches to resolve this:
1. Change your view hierachy (contruct) of your view (don't make detail table view as a cell of the parent table). Make the detail table view as top view, so it could received select action, then maybe, pass this action to (parent) tableview.
2. Add UIGestureRecognizer to both child tableView and parent tableView, then check to perform tap action to both of them
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer
shouldReceiveTouch:(UITouch *)touch

Add multiple buttons to IOS7 Tableview

How would I go about adding several buttons to a tableview to each cell? I need to add a comment and like button to each cell in my tableview and each button will have to be specfic to the row being clicked. How do I go about doing something like this ? Do i place a action inside of
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
or is there a way to programatically set a button to a ibaction from inside cellForRowAtIndexPath that allows me to send parameters?
You can create custom table view cell and add multiple button.
1. Create class that subclasses UITableviewcell with xib
2. In xib delete the view and drag a tableview cell into xib
3. Add multiple buttons in xib
4. Create IBOutlet for each button.
5. In your view controller import your CustomTableViewCell and in CellForRowAtIndexPath method add action for each method and set button tag as indexpath.row
6. Identify the clicked button's indexpath from it's tag
Refer this link
I think this is what you are asking...
[cell.button1 addTarget:self action:#selector(button1Pressed:) forControlEvents:UIControlEventTouchUpInside]; In the
receiver method you can get sender's tag
-(void)button1Pressed:(id)sender{
UIButton *button1 = (UIButton*)sender;
int selectedRow = sender.tag;
}
You need to subclass your UITableViewCell so you can customise it to your need.
There are a lot of tutorials about this. Depends if you are using Storyboard or not. Here is one of many: http://zeroheroblog.com/ios/how-to-create-simple-tableview-with-custom-cells

How to customize a UITableView cell when in "Confirm to Delete" state and the table is in Edit Mode

However I would like to customize the cell when the users touch the icon on the row left in order to display the Delete button. And when he eventually cancel the delete operation (the cell should come back to the previous state).
The table is in the Edit Mode. Therefore the delegate methods are not invoked. (I've tried).
- (void)tableView:(UITableView *)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath
- (void)tableView:(UITableView *)tableView didEndEditingRowAtIndexPath:(NSIndexPath *)indexPath
See third row in the image:
You can handle those events in the cell itself (for that you will need to subclass UITableViewCell). When cell changes its editing state the following methods will be called:
-willTransitionToState:
-didTransitionToState:
Where state parameter is bitmask specifying which UI elements are/will be visible in given cell.

Changing the contentView when an Accessory button is tapped

I've subclassed UITableViewCell to display a UIImage and two UILabel subviews. In the view controller for the table view, in the method cellForRowAtIndexPath: I've enabled an accessory view via setAccessoryType:UITableViewCellAccessoryDetailDisclosureButton.
Cells display correctly.
When I tap on the accessory disclosure button I want to replace the two label subviews with two different label subviews. My approach was the following:
In the subclassed UITableViewCell, inside layoutSubviews, create the
CGRects for the "alternate" labels, position them in the same
places as the two "original" label and hide them via setAlpha:;
When the disclosure button is tapped swap out the set of two
label by adjusting their respective alphas.
The problem is I can't figure out what logic in layoutSubviews I'd use to know whether the accessory button has been tapped. I see that in the view controller accessoryButtonTappedForRowWithIndexPath: is called when that button is tapped and from there it seems like I would call layoutSubviews but can't figure out how to use that fact to accomplish what I'm trying to do.
Am I going about this all wrong? Instead of hiding/showing CGRects with alpha should I simply be creating another subclass of UITableViewCell?
When I tap on the accessory disclosure button I want to replace the two UILabel subviews with two different UILabel subviews.
I'll do the following. Create a public method in your UITableViewCell subclass like the following:
- (void)changeContentForCell;
In this method you could set the contentView as you prefer.
Then in your view controller implement
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{
CustomCell* cCell = (CustomCell*)[tableView cellForRowAtIndexPath:indexPath];
[cCell changeContentForCell];
}
This is a simple example for change the content. In my opinion you don't have to use layoutSubviews to add views.
Leave this logic in changeContentForCell and then call setNeedsLayout to change your layout. Maybe you could have a variable that tracks the state for your cell: normal state or modified state.
Hope it helps.

Resources