I've set the cell accessory to "disclosure indicator" and I have linked that cell with an ctrl - click ("show (eg. push)") to another view. But when I test the app, the cell just becomes grey and nothing more (look at the screenshot). I want this to behave like a Settings-like view.
any hints?
thx, Tim
The disclosure indicatoris just that; an indicator, not a button, so when you make a segue from a cell , with or without a disclosure indicator, it needs to be a "selection" segue. The "accessory action" section of the choices you get when making the segue should be use if you have a "detail disclosure" button, and you want the segue triggered by touching the button itself.
if you want to navigate by code means try this method.
func tableView(_ tableView: UITableView, accessoryButtonTappedForRowWith indexPath: IndexPath) {
//navigateTo your viewController
}
You can find this in TableView Delegate.
Related
In UITableView, when tapping and holding a cell and (without releasing this cell) switching to another screen in tab bar and returning to the initial one, the cell remains highlighted (not selected) and if tapping on another cell, the first one gets selected.
Upon tapping and holding the first cell, tableView(_ tableView: UITableView, didHighlightRowAt indexPath: IndexPath) is called for the first cell. So far it is how it should be.
Upon tapping on another cell (after returning to the screen), tableView(_ tableView: UITableView, didUnhighlightRowAt indexPath: IndexPath) is called for the first cell. And then all methods for selection for the first cell.
Is there a way to remove this behaviour? And upon returning to the screen have no highlighted cells.
cell.setHighlighted(false, animated: false) doesn't work. Yes, it removes highlighting, but selection methods are again called for the first cell.
Have you tried to implement shouldHighlightRowAt and return false?
From the docs for tableView(_:shouldHighlightRowAt:):
Asks the delegate if the specified row should be highlighted.
I want to customise the delete indicator for a UITableView in editing mode.
Since I can't seem to find a way to customise the appearance style of the delete button shown in the first image, I've created my own animation with my own button.
I have deactivated the red standard button using:
func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCellEditingStyle {
return .none
}
Now my question: How do I realize the same behaviour as the standard button? If you press the red button, it invokes a swipe left on the cell showing the wanted delete button.
Help is very appreciated.
i'm having a weird issue with the code on my (static) cells. In multiple cells I have a UIButton. When I click on it, it's all fine, but when I click on the area next to the button (still in the cell itself) it turns grey (color when selected cell) + the button also disappears!
I tried to change the background of the cell to white when pressed with the following code:
override func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
let myBackView=UIView(frame:cell.frame)
myBackView.backgroundColor = UIColor.clearColor()
cell.selectedBackgroundView = myBackView
}
but the issue is still there.
This is when the static cell isn't pushed
This is when I pressed the cell (NOT the button within the cell)
This is a common issue when selecting UITableViewCells, see Why do all backgrounds disappear on UITableViewCell select?
If you don't intend the cell to be selected, implement this delegate method:
- (NSIndexPath * _Nullable)tableView:(UITableView * _Nonnull)tableView willSelectRowAtIndexPath:(NSIndexPath * _Nonnull)indexPath
and return nil when indexPath is the one of your cell. This will disable selection for this cell.
If none of your cells is intended to be selected, it's even easier, just set your UITableView's allowsSelection to NO (this can also be done in Interface Builder).
I have a TableView with 4 static cells, and each cell has a disclosure indicator. The disclosure indicator should fire a segue. This works fine, but only for the first cell. I cannot figure out how to wire up a segue for anything but the first cell, either programmatically or via the story board.
You can use the UITableView delegate like this:
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
// row 1 corresponds to the second cell.
if indexPath.row == 1 {
performSegueWithIdentifier("MySegueID", sender: self)
}
}
In the storyboard, create the segue from the first view controller (not from the cell itself) to the second view controller, and set its identifier to MySegueID``.
I have a table view with a few different prototype cells. I want to have one prototype cell segued to one controller and the rest should not be clickable i.e. no seg.
Right now, I have one button linked to a controller successfully but when I tap on the tableview prototype cell which is segued to a different controller (in the storyboard) nothing happens. I don't get any error either.
What is the best way to go around this? Can I make two different segues in the storyboard? Or do I need to implement something in the tableview method did select row at index path, somehow grab the class associated with the row clicked and programmatically segue to a different screen? Something like:
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
println("here")
//self.performSegueWithIdentifier("profileSeg", sender: self)
}
I am not getting the println here when I select a cell and yes I have assigned the delegate in viewdidload.
EDIT
I've just realised I made a mistake when explaining the question. I actually have a view at the bottom which links to one view controller. It is not a tableview row... This is the seg that works. But I have ctrl dragged to from one type of cell to a second controlleR and that seg is not working. There are also 3 other types of cells none of which have segs attached. Is this anything to do with the issue?
If didSelectRowAtIndexPath not working, it can be caused by either your UITableViewDelegate has not been set, or, it might possible that Selection of your UITableView has been turned off, need to Turn on, see image to find how.
Cheers.
Don't segue directly from cell to 'ViewController', you must segue cell 'ViewController' to the other 'ViewController'. You can segue many times from 'ViewController'.
And please add this code
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
println("You selected cell #\(indexPath.row)!")
if indexPath.row == 0{
performSegueWithIdentifier("profileSeg", sender: self)
}else{
performSegueWithIdentifier("anySeg", sender: self)
}
}
There are two ways to do what you want:
First if you only want to link ONE TVCell with one ViewController you could do what you started to do: Link every TVCell with the ViewController you want to go from there. For that hold ctrl and drag and drop from the prototype to the ViewController. So every TVCellPrototype can have one segue and if you hit the cell it will automatically perform the segue.
This is also the reason why your code don't prints "profile seg".
In this case you don't need to give the segue an identifier.
The second way is better if you need to have MULTIPLE segues from one TVCell to 2 or more ViewControllers. For this you link the ViewController of the TVCells with the ViewControllers you want to go. That way you can set as many segues as you want but you have to give them an identifier because you have to call them in the tableView(... didSelectRowAtIndexPath) function. (click on the segue in interface builder to give it an identifier). This will look like:
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
self.performSegueWithIdentifier("ProfileSeg", sender: AnyObject?())
}
Now lets talk about why you don't get the println("here"):
There has to be a mistake according the function because there is no "override" in front of it. In general the compiler won't build your App because it is missing. I don't have all the code so i can't exactly say whats your mistake.