Selection of tableview cell's index path - objective-c

I have a question regarding the selection of table cells.
I have three grouped tables which are used as forms, only one of which should be in view at a time. So in the nav controller I have a button which presents another table in a popover with the title of all three forms and will control which form is currently available. So to show only one at a time manually is easy enough, but how do I go about detecting the selection of a certain cells indexPath upon selection and communicate that selection with another view controller?

You are getting it as part of
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
for the table view delegate.
Also, it might be worth considering using a segmented control for the selection.

Related

Drag a cell from 1 table view and drop it onto a cell in a 2nd table view to invoke segue

I'm trying to attain a visual interaction between two tables, inside one controller, by dragging and dropping a cell from one table onto another tables cell. When one dragged cell contacts another cell, a segue will be invoked to another controller.
A more detailed description: There are two standard UITableView's inside a UIViewController both that present data in cells utilizing a custom UITableViewCell class (nothing special in terms of what it does) - each cell presents an icon, name & a price. Both tables are placed side-to-side, rather than one on top of the other.
The point of all of this is to have the user tap a cell to create some kind of view object at the tapped location (something that represents the tapped cell) and drag it to the other table view. The dragged object can only be dropped on another cell. This DOESN'T add the dragged object to the other table; the object can only interact with a cell it was dragged & dropped over to invoke a segue to another controller (to do some stuff with the data of the dragged "cell" and the data of the contacted cell).
I've sat on this problem for a while, trying to figure it out. I've tried using touchesBegan & UIGestureRecognizers, but I can't even create some view object upon cell "touchdown" ('didSelectRowAtIndexPath' is useless since it gets called only when the finger is lifted...which null's the ability to drag). Please point me in the right direction or how to solve this problem.
About that touchDouwn event you mentioned, you can achieve that by doing this:
in -(id)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
do
//init the cell "foo"
UIButton * bar = [[UIButton alloc] initWithFrame:CGRectMake(0,0,foo.frame.size.width, foo.frame.size.height);
[bar addTarget:self action:#selector(gotATouchDown:) forControlEvents:UIControlEventTouchDown];
bar.tag = indexpath.row; //use this to know where touchDown happend
[foo addSubview:bar];
now the selector function
-(void)gotATouchDown:(UIButton*)sender{
NSLog(#"I just touched row nr %ld ",sender.tag);
}
Not sure what to do next, once I figure it out I'll complete my answer.

Expansion for a view-based NSTableView

I have a view-based NSTableView for which some cells have enough content that it doesn't fit. I would like to be able to have the cell automatically expand when a user hovers their cursor over the cell.
In searching for this, it seems that this is the default behavior for a cell-based NSTableView. There are even methods like shouldShowCellExpansionForTableColumn, which the doc says is for cell-based table views only. Somewhere else in the doc implies that this expansion behavior is even on by default for cell-based table views?
- (BOOL)tableView:(NSTableView *)tableView shouldShowCellExpansionForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
I get the impression that I'm missing something obvious.
Goal:
Be able to put multiple rows of NSTextField objects in a view-based cell (more than there is pace to handle)
If the content overflows, put a visual indicator into the cell
When the user does a tool-tip style hover on the cell, expand the view to show all the content
You seem to be on the right track as this should work for cell based NSTableViews. You need to put tableView:shouldShowCellExpansionForTableColumn:row: in the tableView's delegate. You could reply YES for the column of interest.
With a view based table where you use NSTextFields these scroll, truncate or wrap but there is not an expand on hover option. It is possible to set the tooltip text to be the same as the content which might be a reasonable solution.
Did you try to change the row height (tableView:heightOfRow:) triggered by some mouse action? You might have to reload the tableview.

UITableViewCell: deselect immediately after didSelect or when come back from pushed VC?

I've seen people doing this differently, I would prefer that when you select an item in UITableView (say in screen A), the item is highlighted(selected), and another screen B is pushed to the navigation stack, then when you go back from screen B to screen A, the previously selected item will be unselected with animation, so what you do is to put:
[self.tableView deselectRowAtIndexPath:[self.tableView indexPathForSelectedRow] animated:YES];
inside:
- (void)viewWillAppear:(BOOL)animated;
and this is what Apple's sample code does. But I've seen a lot of people deselecting the row just after it is selected, inside:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
I know it may be just a personal preference, but I wonder is there any official clarification on this? Deselecting in viewWillAppear: lets users know his/her previously selected item, which is a bonus, but for some custom cell, the selected background/view may not be just solid color, and they may have a UIView added to the cell to represent the selected state, which makes the app inconsistent if some cells are deselected with animation and some are straight away after selected without animation.
Does anyone have any idea?
It's something that's up to you, if you are customising your applications UI extensively then you might not want to use this highlight at all. Maybe you have a complex cell and instead of using the cells selection trigger to drill down into a detail view or other, maybe you'll have a UIButton inside you cell.
It seems to me that UIKit wants to highlight the cell and retain it's highlight until you pop the detail view controller, at this point, presumably in viewWillAppear:, the currently selected cell of the UITableView is deselected, this allows you to have a very subtle and brief indication of which cell was selected to access where you've just come from.
Doesn't sound too interesting said like that however imagine if you exit the app and return some hours later, it's nice to have this small and as I said very subtle animation.
In the applications I've done in the past I've tended to not use this so much, or select but deselect immediately, so the user doesn't see a deselection animation upon returning or going "back" to the list. But that said all my cells in the applications I'm referring to have been very heavily customised.

How to make a click on TableViewCell open a new view and keep data?

So I've added a UITableView in a UIViewController. I also subclassed its TableViewCells to look like this :
Now I just want to know how I can click on the cells to open a new view with another TableView containing a selection of options, and to write the selected option instead of the "This is row : %d" line. (everything is embedded in a NavigationController)
Thanks a lot for your help.
You can use UItableview Delegate
(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
You will get click event. In that you can use indexPath.row for retriving string from your data source array (which contains data you shown in cell.) on which user has clicked. Now you can open (push)new view controller using navigation.
Pass the indexPath.row or particular string to your next view controller so that you can get which one is get selected.

How do i add UITableView in the UITableView cell?

I Have one tableview(First) in that i want another tableview(Second) in the cell of first tableView.
In short i want each cell contains one more tableview.
So help me out with this problem.
Thanks in advance.
Although I think the below method is better this tutorial shows you how to create a tableView inside of another tableView http://iosstuff.wordpress.com/2011/06/29/adding-a-uitableview-inside-a-uitableviewcell/
My Solution:
That approach is bound to run into serious problems, so I suggest scrapping it. If you have nested table views (or scroll views, more generally) then the scrolling behavior of the views will be erratic. A better solution is to use variable height table view cells: you just create the cell view to hold all the multiple choice options you need, and implement
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
in your table view delegate to supply the heights of the cells.