1

I have implemented a image slider with a UICollectionView inside a UITableViewCell which the user can slide to left and right. I want to create two buttons on this UITableViewCell so the user can also tap on that buttons to slide the images.

I've done this by adding the buttons on the images inside the UICollectionViewCells but with that the buttons also are swiping when the user swipes to left or right or taps the buttons.

I tried to fix the buttons on the UITableViewCell, but anyhow the buttons does not get displayed, when I do it like this.

So how can I achieve this, that the buttons are fixed inside the UITableViewCell and the UICollectionView inside the UITableViewCell can move it cells without effecting these two slider buttons?

At storyboard it looks like this:

enter image description here

Can't rearrange the buttons: enter image description hereenter image description here

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Kingalione
  • 4,237
  • 6
  • 49
  • 84
  • Please post code – Alistra May 30 '17 at 08:09
  • If you do not want the buttons to move along the collection view's contents, place the buttons outside of the collection view cell's view hierarchy, on the same level as you collection view (in the view hierarchy of your tableview cell). The buttons should go on top of the collection view, not the cell. – bajocode May 30 '17 at 08:16

1 Answers1

1

Add the buttons directly to the content view of the table view cell, don't add them to the collection view. That way they will stay in position. If you can't see them it's possible that they were underneath the collection view and were obscured. Change the order of the views in interface builder by dragging and dropping in the document outline. This changes which view is on top.

The document outline is the view you have posted as a screenshot in your question, starting at "brandsCollectionTableViewCell". The outline contains the subviews of the cell. Views with the same parent, like the image view, label and buttons currently shown in the outline, will be ordered "on top" of each other by their position in the list. So you drag the items in that list to change the order, or select the buttons then go to Editor -> Arrange -> Send XX to adjust the position.

Use the Xcode view hierarchy debugger to help you understand what is happening (that's this button on the debugging toolbar):

enter image description here

The 3D view will let you see where your "missing" buttons are.

If you really want to include the buttons in the collection view, then you need to use a custom collection view layout implementing floating views. That's not a straightforward task, but I've written something about it here.

jrturton
  • 118,105
  • 32
  • 252
  • 268
  • How can I "Change the order of the views in interface builder by dragging and dropping in the document outline" ? I didn't understand this part of your answer. And you are right the missing buttons are under the collection view and just not visible but still there. – Kingalione May 30 '17 at 08:38
  • I've added some more detail to the answer – jrturton May 30 '17 at 08:43
  • thank you for your help. I tried the way you explained but the arrange fields are disabled in my xcode. I updated my answer to show it to you better. – Kingalione May 30 '17 at 09:20
  • I found the solution for this problem here: https://stackoverflow.com/questions/18194777/in-xcode-interface-builder-why-are-the-options-in-the-editor-arrange-menu thank you anyway – Kingalione May 30 '17 at 09:28