I am learning about TableViews in Xcode right now and I am having trouble finding some info on TableViewCell accessories.
My goal is to have a MasterTableView and a SubTableView. When a MasterTableCell is tapped to take the user to the SubTableView. But I'm stuck with something simple like showing a '>' on the right side of the cell to show that it has a SubTableView.
Do I need to design my own button? I thought there was a navigation image already available to me in the UI storyboard maker but it won't let me drag and use it in my custom cell I'm making.
Any thoughts or links to documentation would be great. I've looked in the developer library and all it tells me is that it is possible, not how to do it.
Thank you in advance.
If you are using a Prototype Cell in the Storyboard, just set the "Accessory" type in the Attributes inspector to "Disclosure Indicator".
If you create the cell programmatically, set
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
From the documentation:
UITableViewCellAccessoryDisclosureIndicator
The cell has an accessory
control shaped like a chevron. This control indicates that tapping the
cell triggers a push action. The control does not track touches.
Related
I have a UICollectionView which allows for a user to select a cell and upon doing so view 'A' will appear. I am wondering if it is possible for the subviews of this cell, ex: UIlabel and UIImageView to provide a different functionality for when they alone are selected. For example, if the UIImageView is selected, I want to segue to view 'B' as opposed to 'A'.
I have attempted to implement a UITapGestureRecognizer for both the label and the image, however, the cell's functionality overrules and the resulting view is still 'A'. Any ideas?
Thank you in advance.
What you want to achieve is possible through delegates if you don't have custom cell make a custom cell class then inside custom cell declare your protocol
I assume you have to disable the default behavior of the collection view cells:
cell.selectionStyle = UITableViewCellSelectionStyle.none
However, if you set that and you encounter an overlap issue, please take a look at the 'cancelTouchesInView' property of the 'UITapGestureRecognizer'. Basically, by setting that to false, you allow the children to also receive touch actions.
Furthermore, do not forget each gesture recognizer should have it's own method for you to be able to segue into two different places.
(Xcode 7.3.1, iOS9.3, Swift)
I'm struggling with setting up an UI Test in my assignment for what would seem to be a fairly standard and common use case.
I have a sub-classed UITableViewCell which contains a textField that does not fill the entire cell and has the Disclosure Indicator set. The user is able to type the data into textField by tapping on it, but if they tap outside the textField, but still in the cell, my app segues to another view. The project works fine and the child view receives the correct data from the cell's textField.
My Master-Detail app has UITableViews on both the Master and Detail views. My UI Test selects the first cell in the Master View, waits a little for the DV and then selects the second cell in the detail view, which is configured in accordance to my earlier description.
I am simulating a tap on the second cell using
tablesQuery.cells.elementBoundByIndex(1).tap()
However, the simulator interprets it as a tap in the textField, so no segue occurs. I have read SwiftyCruz's question and the given answers but his use case is a little different, as I'm not using a Detail Disclosure, also the accepted answer doesn't translate to my situation. In following ferunandu explanation, I have tried setting the Accessibility Label and Identifier on the Cell as well as a different string for the accessoryView?.accessibilityIdentifier. Though UI Test still doesn't work, ferunandu's snippet does change the disclosure indicator from > to a blue box.
Using a breakpoint, I've been querying the app object in the debug window trying to find the right control, but to no avail. I am able to find the textField using indices as well as the identifier, but nothing I've tried has returned .exists true for the accessoryView.
Am I trying to access the cell incorrectly? Or, is it actually not possible to do what I'm attempting?
The code for my test is:
XCUIDevice.sharedDevice().orientation = .Portrait
let app = XCUIApplication()
wait()
let tablesQuery = app.tables
tablesQuery.cells.elementBoundByIndex(0).tap()
wait()
tablesQuery.cells.elementBoundByIndex(1).tap()
What am I not understanding properly here? Any advice would be greatly appreciated.
(I know I could have used a standard UITableViewCell with the data entry done on the child view, but I prefer not to change the design of my app to accommodate XCTest's, seems a bit backwards.)
I have a sub-classed UITableViewCell which contains a textField that does not fill the entire cell...
I am simulating a tap on the second cell using
tablesQuery.cells.elementBoundByIndex(1).tap()
However, the simulator interprets it as a tap in the textField, so no segue occurs.
It sounds like your tap on the table view cell is being intercepted by the text field. When UI tests tap on a table view cell, the tap will be at the centre of the UI element's frame.
To offset the tap location from the centre of the cell, use coordinate(withNormalizedOffset:) and tap the coordinate instead of the element directly.
let cell = app.tables.cells.elementBoundByIndex(0)
// Retrieves coordinate that is 50% of the way along the cell
// and 20% of the way down the cell - adjust these values to
// find the right values to avoid tapping the text field area
// of the cell
let cellCoordinateForTap = cell.coordinateWithNormalizedOffset(CGVector(dx: 0.5, dy: 0.2))
cellCoordinateForTap.tap()
I'm building an app where I've got cells that expand, similar to when you create a new event in iOS' built in calendar app. One of the expanding cells have a disclosure indicator set in storyboard, but return nil when logging it. I've tried to set it both in StoryBoard and like this:
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
and I'm trying to fade it out like this:
self.cell.accessoryView.alpha = 0.0f;
but it doesn't work as it's nil.
Can someone help me with this? Why is it nil? I'm using StoryBoard with a UITableViewController that's static and grouped.
Thanks!
Erik
You'd have to provide your own accessoryView. accessoryView will be nil if you're using an accessoryType.
Remember to add a little logic in tableView:cellForRowAtIndexPath: to decide whether or not to show your accessoryView as well since the cells get reused.
I am not sure, whether Question heading is explanatory. I have the images here
The first Image shows a UICollectionView. On the Click of any cell, it should turn into Image 2. i.e. a new popup will come up, and the Cell 3 and Cell 4 will move down. or I can say on click of cell 3, cells 5,6 will move down. How to this? How can I show this Animation?
Please help. need more info?
One Solution, could be, is to a reusableView at footer, showing and hiding it. But I need more efficeint way
I have to design this app for iPhone and iPad too
Just define multiple UICollectionViewCell classes, register them in your controller class and insert items to model on user actions. In that case red cell at "Image 2" will be just another UICollectionViewCell instance.
I created a Custom UITableCellView for my application. Each cell has two buttons. The problem I am facing is that the cell itself is selectable which leads to a confused user and poor design. How do I disable the interaction for the cell but keep the interaction enabled for the UIButtons in the cell?
Thanks!
Satyam
You can set the cell.selectionStyle = UITableViewCellSelectionStyleNone; and be sure to keep your didSelectRowAtIndexPath unimplemented. That means that your cells will not be interactive, but you can still get messages from your buttons.
Apart from that, of course I don't know what you're trying to achieve, but remember that you can use a UITableViewCellAccessoryDetailDisclosureButton as an accessory view, which is a different "button" from the cell itself. More info here.