I have 2 sections in my UITableView.
I want the first section to allow multiple cell selection and the second section to allow only single selection.
I tried some code but didn't work very well.
Code in swift if possible. Thank you.
相关问题
- “Zero out” sensitive String data in Swift
- SwiftUI: UIImage (QRCode) does not load after call
- Get the NSRange for the visible text after scroll
- Custom UITableview cell accessibility not working
- UIPanGestureRecognizer is not working in iOS 13
相关文章
- UITableView dragging distance with UIRefreshContro
- Using if let syntax in switch statement
- Enum with associated value conforming to CaseItera
- Swift - hide pickerView after value selected
- Is there a Github markdown language identifier for
- Popover segue to static cell UITableView causes co
- How can I vertically align my status bar item text
- Adding TapGestureRecognizer to UILabel in Swift
Perhaps you could implement the table view's delegate methods:
tableView(_:shouldHighlightRowAtIndexPath:)
and
tableView(_:didSelectRowAtIndexPath:)
...and determine (from
indexPath.row
andindexPath.section
) if the relevant section supports single/multiple selection (this will depend on your data model's custom logic -e.g.: "Section0
supports multiple selection but section1
does not"), and if it only supports single selection, check whether there is already a row selected (by accessingtableView.indexPathsForSelectedRows
).If there is a selected row already, you can:
false
fromtableView(_:shouldHighlightRowAtIndexPath:)
, andreturn
) fromtableView(_:didSelectRowAtIndexPath:)
(I'm not sure if this method is actually called when you returnfalse
fromshouldHighlight...
, so perhaps check it).This is easily achievable in two lines as follows: (Swift 4)
You can simply try this. This solution works for me perfectly. Give it a try maybe worked for others...
Swift-4
If you want the selected row in section 2 to be the new selected row, this might work for you. Else, go with @NicolasMiari's answer.
Not very elegant, but hopefully it will give you an idea.