UIAutomation recording doesn't work properly with UITableViewCell - ios

I have a simple app that shows table view with 3 cells.
1. First cell has only button.
2. Second cell has button and label.
3. Third cell has only label.
When recording with Xcode instruments, the code is not generated properly:
var target = UIATarget.localTarget();
//tap background of each cell
target.frontMostApp().mainWindow().tableViews()[0].cells()[0].buttons()["Button"].tap();
target.frontMostApp().mainWindow().tableViews()[0].cells()[1].tap();
target.frontMostApp().mainWindow().tableViews()[0].cells()[2].tap();
//tap button of each cell
target.frontMostApp().mainWindow().tableViews()[0].cells()[0].tap();
target.frontMostApp().mainWindow().tableViews()[0].cells()[1].tap();
//this cell has no button
//tap label of each cell
//this cell has no label
target.frontMostApp().mainWindow().tableViews()[0].tapWithOptions({tapOffset:{x:0.49, y:0.25}});
target.frontMostApp().mainWindow().tableViews()[0].tapWithOptions({tapOffset:{x:0.40, y:0.43}});
It seems like recorder doesn't recognize pressed view and inserts something else instead.
Is this bug in Xcode tools or behaviour somehow related to UIAccessibility?

Related

iOS 13 UISegmentedControl inside UITableView caches previous selection

I have a screen with UITableView which displays one row per data element available, count of data element can be in hundreds. Depending on the data element type, each rows shows either an input field or segmented control. There is problem with the segmented control in iOS 13, when user taps first or second segment of a segmented control row on the top of the view and scrolls down, it auto select first segment for some random segmented control row in the subsequent scrolling view/page. It looks as if the control state is not refreshed.
Here is the code snippet of cellForRowAtIndexPath function where it creates the UISegmentedControl row.
QuestionOnTopTableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:#"YesNoInputIdentifier"];
if (!cell) {
cell = [[QuestionOnTopTableViewCell alloc] initWithCellStyle:QuestionCellStyleYesNo reuseIdentifier:#"YesNoInputIdentifier"];
}
cell.titleLabel.text = row.title;
cell.segmentControl.selectedSegmentIndex = row.answer ? row.answer.boolValue : UISegmentedControlNoSegment;
Any one ran into this issue?
Note: This issue happens only on iOS13.
The system will only allocate enough cells to visually display, and then when one scrolls off it reuses it for the new cell scrolling in. As a result - when this happens it remembers the previous selection as you're seeing.
Not sure why this wasn't happening pre iOS 13 (it does look like your cellForRowAt: function should set the correct value if you're looking at the right row variable, but you should just be able to reset it by overriding the UITableViewCells prepareForReuse() method.
Swift
class QuestionOnTopTableViewCell: UITableViewCell {
// stuffs
override func prepareForReuse() {
super.prepareForReuse()
self.segmentControl.selectedSegmentIndex = .noSegment
}
}
Obj-C
This should work for you:
-(void)prepareForReuse{
[super prepareForReuse];
self.segmentControl.selectedSegmentIndex = UISegmentedControlNoSegment;
}
Edit:
I actually did just see another question claiming .noSegment doesn't work anymore after a value has been set on iOS13/Xcode 11 builds: UISegmentedControl.noSegment stopped working with Xcode 11, iOS 13
What you may need to do instead, unfortunately, is recreate a local version of the segmented control every time and overriding the control: cell.segmentControl = myNewJustCreatedSegmentControl
you can perhaps still do that in the prepareForReuse method

UITableViewCell didSelectRowAt: not getting called when press on UIButton area in cell

I have added UIButton(for some functionality requirement in project.) with checkbox image. Checkbox image select and unselect working proper on UITableViewCell tap but if I tap cell on checkbox button area button image isn't changing. I mean didSelectRowAt method isn't calling.
I found solution. I have checked that UIButton's UserInteraction ignores UITableViewCell's tap.
So I have just added below line in my code. And cell tap working good.
cell.btnCheck.isUserInteractionEnabled = false

How to keep subview on UITableViewCell

When the user taps the accessory view, the profile image in the UITableViewCell gets darkened by a black view that gets added on as a subview.
Here is what the cell looks like with the black subview:
Here's the issue: When I tap on another cell, the subview gets removed from the first cell and added to the second:
I would like to keep the subview for all cells that have been tapped.
Here is the code in which I handle that functionality:
self!.profileImageBlackView.cornerRadius = cell.followUserImage.frame.height/2
self!.profileImageBlackView.frame = cell.followUserImage.frame
cell.followUserImage.addSubview(self!.profileImageBlackView)
cell.followButton.hidden = false
For some reason, the follow button gets added to both cells, but the "profileImageBlackView" gets moved from cell to cell depending upon which one was activated.
You cannot display the same view in different cells. If you add the view to another cell it's removed from the first one. You must create a separate view for each cell.

iOS Accessibility fail to focus next tableviewcell

I have tableview with these tableview cells:
- cell have some collectionview and cell have Height larger than haft of screen
- cell have other tableview inside it
When access to the last item inside cell (collection cell or tableview cell inside), i swipe right to focus on next cell. But it not jump to next cell in tableview, It jump to other item on screen
Example: i have main tableview, in this table have some cell is expanded cell which have other small tableview inside it. When this cell was expanded and i swipe right to last item of small tableview, then i swipe right again to move to next cell of main tableview view. But this time the next cell of main tableview was not focused, but some other item in screen gets focus
Could you give me the hit! Thanks a lot.

Display label in UITableview cell When its visible in Ios

I am new to iOS. I need to show the Label in timeDelay in UITableViewCell only when its visible?
Create a custom UITableView cell. In your cellForRowIndexPath, call the function performSelectorWithDelay which will show your UILabel.
When the cellForRowIndexPath is called, it's pretty certain that the cell will now be shown.

Resources