When I use self.title in any other place except viewDidLoad, nothing happens. I am trying to change the text of the navigation bar on my UIView.
I am trying to get the text off of a table cell when selected, and then make the title of the UITableView (which will show right after I touch the table cell) the text of the table cell. What is the easiest way to do this?
UINavigationItem's title inherits the value from the associated UIViewController's title, but it does this by copying the value at the time that it needs it. Once your navigation item has been added to a UINavigationBar, in order to change what it displays you need to modify the item itself, e.g. by assigning to self.navigationItem.title.
Related
I want to make a custom text selection in my table view.
I found this awesome answer on how to set the colors, fonts, etc. of the cells.
However, there is one issue.
It does not work for group rows. I see that the method gets invoked, but I think the style gets overwritten somewhere in either the NSTableCellView, or in the NSTableView class.
How can I fix this?
EDIT
It's a view based NSTableView
I have dragged an item into my tableview object.
When the dragged item hover over an item in tableview,
the item is redrawn with selection background. The image is as under
The row of the tableview is not selected, when i checked selectedRow method.
My requirement is when an item hover any item i should control its selection
and the background selection thereof.
Thanks,
iSight
To 'control' the selection of a TableViewCell when 'hovering' over such an item you will have to call this method:
- (NSIndexPath *)indexPathForRowAtPoint:(CGPoint)point
It's a method from the UITableView Class and uses the local coordinate system of your tableView. As is mentioned in the Apple Doc: http://developer.apple.com/library/ios/#documentation/uikit/reference/UITableView_Class/Reference/Reference.html
When the method is called you will have a NSIndexPath returned. With it you can select the cell/item at that particular path.
Mind, selecting a path manually doesn't call the didSelectRowAtIndexPath delegate-method so if you want a certain method called from that delegate you will have to do that manually as well!
This method is prolly called from the touchedDidMove method (where you also do the drag&drop) so getting the point needed for the method shouldn't be a problem for you.
You will figure it out :)
Good luck.
I have embedded UIButtons in my TableViewCells. In order to track which cell the button belongs to, I would like to add an NSIndexPath property to UIButton. I do not want to subclass a UIButton. Is there a way I can do this with categories?
EDIT: I believe the idea of setting tags will not work if I have multiple sections in the table view. Another approach of accessing the button's superview's superview to determine the cell seems more like a hack. Looking for a cleaner way of doing this.
There are several approaches. If you just really need a single number rather than a full index path, you can use setTag:. It's inflexible, but it's readily available.
The next best solution is associative references. These can hang data onto any object, with proper memory management. I usually create a category that adds a property implemented using objc_setAssociatedObject and objc_getAssociatedObject.
You can find out which cell a clicked button was in without having to associate tags or index paths with the buttons, which can get messy when re-using cells. Tags do work with sectioned tables but you have to mess about with numbers, e.g. 10001 is section 1, row 1, so you've got to convert at one end and convert back at the other, too fragile for my liking.
A nicer method is to use UITableView's indexPathForRowAtPoint: method. When your button's action is activated (assuming the target is in your table view controller:
CGPoint point = [sender convertPoint:sender.center toView:self.tableView];
NSIndexPath *path = [self.tableView indexPathForRowAtPoint:point];
sender here is cast to UIButton.
In order to track which cell the button belongs to
You already know which cell the button belongs to: it's the cell that the button is a subview of.
Start with a reference to the button. (If you are the button, this is self. If you're the button's target for its action, then when the button is tapped and emits an action message, it passes itself along as parameter to the action message, usually called sender.)
Look up the view hierarchy (superview) to find the UIViewTableCell containing the button.
UIView* v = theButton;
while (![v isKindOfClass: [UITableViewCell class]]) v = v.superview;
Now you can do whatever you like with that info. For example, you seem to want an NSIndexPath; then call -[UITableView indexPathForCell:].
I'm trying to add an NSTextField as a subview of a custom view class I have (which subclasses NSView), and then make the NSTextField the first responder. This works fine. The text field shows up and I can start typing in it. However, any mouse events in the text field seem to fall through to its superview. For example, I can't see the mouse cursor when I hover over the text field, and when I click anywhere in the text field, it attempts to resign firstResponder status instead of letting me select text within the text field.
I'm not overriding hitTest or anything weird like that, and I only have one window, which is definitely the key window. Any ideas?
Thanks in advance! :-)
I'm using a tableview to display a list of rows and when selected, I want additional controls to appear right below the cell, probably in another view which I will control.
So far, I've managed to get a reference to the selected cell by running through the visiblecells array in the tableview but the frame property always returns a y-coordinate of 0 no matter what scroll position the table is in.
How do I get the position of the cell relative to the window?
I think the best way to deal with table views is in their own terms. That is, if you want to position something new inside the table, put it in a cell. It sounds like you want to subclass UITableViewCell to make your controls, and go through the whole tableView beginUpdates - insertCells - endUpdates process to animate their appearance.