Select row when cell in tableview is a tableview iPhone - ios

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

Related

Pass a View from One controller to Other Controller iOS

I have tableView in first controller and i am making it with tableviewcells defined in xib. Now when i click on one tableviewcell i need to open a present view controller and pass on the View of tableviewcell to second view controller.
I am using a init method in second view controller and passed the cell.contentView of 1st VC to 2nd VC.
It is working fine tableviewcell content view is getting shown on the 2ND VC first table section but when i press close to the 2nd VC .The TableViewCell content view disappears from first VC.
I am not able to so. I have seen on net they are saying register XIB again on 2nd VC , or use archive and unarchive but these are time consuming operations and i just want to pass a tableviewcell content view to 2nd vc and when i close 1st VC i want it back there.
Any help would be appreciated.
View is the cell.contentView of the pressed tableview cell
self.superViewCell = View;
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
HVAPParentTableViewCell * cell = [[HVAPParentTableViewCell alloc] init];
[cell.contentView addSubview:self.superViewCell];
return cell;
}
The cell is probably missing in the 1st view controller because you removed its contentView and passed over to the 2nd view controller. This is clearly an anti-pattern you probably don't want to use. You may want to pass over to the 2nd view controller cell's "state" rather than its contentView though, and initialise a new cell with the same cell data.
Having little knowledge about what you're actually trying to achieve, my general advice would be to register the 2nd view controller's table view with the same xibs and cell identifiers as in the 1st view controller. Now you can pass over only the selected cell's identifier (so that you know which one to use when dequeueing in cellForRowAtIndexPath for the passed-over cell) and cell's data. Then you can initialise the same cell in 2nd view controller with cell's data from 1st view controller.

iCarousel View in a table cell view does not scroll at all

I put the iCarousel View in a table View and try to scroll the iCarousel, but the problem is it's not scrollable at all.
I can see iCarousel in the cell like following:
and I put iCarousel datasource and delegate in the tableView Controller, create a customer function to set the iCarousel datasource and delegate.
In the CustomTableViewCell I just define the setting delegate function:
- (void) setICarouselDataSourceDelegate: (id<iCarouselDelegate,iCarouselDataSource>)dataSourceDelegate {
self.carousel.dataSource = dataSourceDelegate;
self.carousel.delegate = dataSourceDelegate;
[self.carousel reloadData];
}
and in the MainTableView, I call the DataSourceDelegate in the
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
First of all iCarousel is not any standarad View ... you should put link of the control that you're using
Second it seems like iCarousel is uses UIScrollView and UITableView is also derived from UIScrollView It's never a good idea to put a scrollview inside another scrollview.
This might be the reason why your table view is not scrolling.... BTW are you talking about horizontal scrollign or vertical scrolling ?
Currently I am using the iCarousel in Table View cell and it scrolls easily.
Just add standard view to cell in Storyboard.
In IB mark the class of that view to iCarousel.
Furthermore !ENABLE! user interaction on that view. (Maybe because of that you can't scroll the content inside the cell)
Implement separate datasource & delegate for every cell. (It is more clear which data are loading in the cell and also the cell itself can handle the data. You just pass the data to cell and it handles it accordingly.) - But it depends on you if you want to let one class to handle two separate control datasources & delegates :-)

Scroll to selected cell in UITableView after selecting cell in UISearchDisplayController?

I want to set up a UISearchDisplayController such that after a cell is selected from the search results, the search display controller is dismissed and the table view scrolls to the selected cell. Here's my code:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (tableView == self.searchDisplayController.searchResultsTableView)
{
[self.searchDisplayController setActive:NO];
// scroll to selected cell in table view here
}
}
I know the method I need to use is:
scrollToRowAtIndexPath:atScrollPosition:animated:
However, this method needs an index path from the main table view, not the search results table view. How can I get this index path?
What does your datasource look like? Perhaps you can query the datasource based on what was selected in the search results to get the cell's index.
Sounds like a strange user interaction not knowing what you're doing though. Normally searching and then selecting will take you to that record's details or select it as an option or something.

UITableView inside UITableViewCell

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.

How do I respond to touching an empty UITableViewCell?

I'd like to launch my "add item" form in response to touching an empty cell (the next blank cell), sort of like the stock "Reminders" app. didSelectRowAtIndexPath doesn't work for this and I don't have a clue what does.
Thanks
add a button to the tableFooterView
https://developer.apple.com/library/IOs/#documentation/UIKit/Reference/UITableView_Class/Reference/Reference.html
You could add a tap gesture recognizer to the table view, but be sure to test if the user tapped a table view cell or not.
If you wanna the last cell of your table view to be an add button so that you can add a cell directly without putting the table view in edit mode, then here is what you can do:
For the array you use to populate the table view, always make sure the last cell is a dummy object you use to add a row only.
in your -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath, make sure check whether indexPath.row is equal to [array count], if that's the same, then
insert whatever the object you create to your array at index = [array count]-1.
Call your [tableview reload] method. Then you will see the cell append to the table view.
Hope this helps.

Resources