I have a UICollectionViewCell with .xib.
Here is the Structure of the xib file
As you can see every element at the same level and 3 image views and a single button. But at run time there is a UIView in front these elements.
UI structure at runtime.
I need to understand why this is happening and what is the solution. Because of this overlay UIView clicks events not pass down to the button.
Problem was I was using UIView in the XIB that created by default when creating a xib file. Instead of using that I tried with UICollectionViewCell element as the parent and it worked for me.
Related
What I'm trying to achieve:
Trying to achieve Google-Now-style like custom TableViewCell with couple of buttons on each card (refer to the provided screenshot here). Using Storyboard.
Problem
I was able to make the card like TableViewCells, but whenever I try to place a UIButton on the card, it will either cause a compiler error or a runtime error.
Current setup
My current storyboard set up looks like this.
Here's my code for the TableView.
What I've tried so far
Drag and dropped the UIButton on top of my card view, which looks like this. Button get buried down somewhere under the tableview? Button does not appear like it should and once I create an outlet to the actual code, compiler error (invalid outlets cannot be connected to repeating content).
Placed the UIButton on top of the Content View. This outputs in same result as above.
Placed the UIButton on top of the View. Now this actually shows the button on the storyboard, however it causes a runtime error and crashes while it tries to display this ViewController.
Here is how it's set up on the Storyboard.
Now, what am I doing wrong here? I've looked at several tutorials on how to place a UIButton on a TableViewCell and it looks dead simple as just placing the UIButton on top of the cell.
EDIT: So I did add a new class for the petListCell and assigned it on identity inspector. I place it on the Card Design View, where the button should belong to, and it is now giving me following compiler error: "/Users/.../Main.storyboard: The feedingHistoryButton outlet from the YourWoofsViewController to the UIButton is invalid. Outlets cannot be connected to repeating content."
You need do like this.
create a subclass of UITableViewCell like PetCell
change the class of the cell in storyboard from UITableViewCell to PetCell
link the button to PetCell like you did with the ViewController
You can change this.
create First a subclass of UITableViewCell like PetCell
And change the class of the cell in storyboard from UITableViewCell to PetCell
link the button to PetCell like you did with the ViewController
The top level container view is a custom UICollectionView. I have added two custom container views on top up location. The hierarchy tree is like below
custom UICollectionView
|- custom UIView container => 1 ImageButton
|- custom UIView container => 8 Buttons
|- custom UICollectionCells
Voice Over could respond with these buttons correctly.
But when I tried to use UIAutomation with target.logElementTree(), the element tree only finds the UICollectioncell list under the cutom UICollectionView, It cannot find the custom subview container and their children.
Then I tried Xcode UI Testing, using app.debugDescription. The result still only contains UICollectionCells in the custom UICollectionView, without buttons.
How could I make them appear in the UIAutomation element tree?
Finally by using Aspects with the custom collection category:
In custom collection category, override +(void)load:
add aspect block to init the stong property a, which storing all accessibilityElements after execution initWithFrame:collectionViewLayout: or initWithCoder:
add aspect block to add subview to property a after execution addSubview:
finally, implement UIAccessibilityContainer protocol methods using the property a
Tricky part:
use objc_setAssociatedObject and objc_getAssociatedObject to handle a
I am trying to add a container view to a UICollectionViewCell in interface builder but Xcode issues an error error: Illegal Configuration: Container Views cannot be placed in elements that are repeated at runtime. Will making the UICollectionViewCell static would solve this? If so, how would you make the UICollectionViewCell static?
What I guess you are trying to do, is placing a UIViewController into a dynamically generated UITableViewCell.
If so, this isn't possible if the cell you are generating are dynamic. If you know a priori that the cells will always be in a fixed number, you can generate them by Interface builder setting the cells to static.
If instead you only want to add a container view to your cell in order to put other objects in it, you need to add a UIView object, not a UIViewController.
I know this issue isn't new and there are many similar questions like this on this site. I've checked most of them but cannot find the answer.
I have a UITableView. Inside each UITableViewCell, I insert some of subviews (same level). One of subviews is a UIScrollView that I use to add some UIIMageView to scroll horizontally. The ScrollView is the bottom subviews (other subviews are above this ScrollView). I've made a test project and pushed to GitHub: https://github.com/lenhhoxung86/PageControlDemo.
The project works file and I noticed that delegate method: - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath is not called but it's just fine.
However, when I moved this code into my real project, it doesn't work and the delegate method of tableview (didselectRowAtIndexPath) is actually called.
Can anybody help me fix this? I'm going to insane for this issue. Following is picture captured on my test project
Finally I found the cause. In my test project, I used a Xib file created when I created a custom class of UITableViewCell. The view object is kind of class UITableViewCell by default. In my real project, I created custom class UITableViewCell first then created many Xib files so that I can load them when I need. By default, these View objects in these Xib files are kind of UIView. I re-created Xib file that belongs to class UITableView by default then it works. I have no idea how to convert existed Xib file with object of UIView type to UITableView.
I'm building an interface in codes from scratch (there's nothing in XIB file). I'm adding a tableitem that consists of some cells and those cells contains one or more views (UIButton, UITextField, etc.)
The problem is none of the items are clickable/editable! When I click TextFields or Buttons, nothing happens! No highlighting, no cursor changing nothing at all...
What I'm missing here?
Also constructed the cells programmatically. I am adding controls directly to the UITableViewCell.
One possible issue: some of your views (may be ContentView or the UITableViewCell) hides the controls from manipulation. You should set that [UIView].userInteractionEnabled to false. You can also try to implement touch listeners to your views to recognize which one hides your controls.