Questions tagged [indexpath]

167 questions
22
votes
7 answers

Swift 3 Array, remove more than one item at once, with .remove(at: i)

Is it possible to remove more than one item from an array, at the same time, using index locations as per .remove(at: i) kind of like: Pseudo code: myArray.remove(at: 3, 5, 8, 12) And if so, what's the syntax for doing this? UPDATE: I was trying…
Confused
  • 6,048
  • 6
  • 34
  • 75
12
votes
4 answers

How to check if IndexPath is valid?

Prior to swift 3, i used to use for example: let path = self.tableView.indexPathForSelectedRow if (path != NSNotFound) { //do something } But now, since i use IndexPath class in swift3, i'm looking for the equivalent for the path != NSNotFound…
Lirik
  • 3,167
  • 1
  • 30
  • 31
11
votes
4 answers

How to display ads within a collection view

I'm trying to add some banner ads randomly inside my collectionView. Each collectionView cell would be a basic image (black square here to make things easier) populated dynamically from an array (let's say it's a really long array and call it…
user7098356
7
votes
4 answers

How to get indexpath from row index Swift

I am loading an array to UIcollectionview(later will add other data) . I want to select collection view item randomly as: var indexpath = Int(arc4random_uniform(UInt32(items.count)-1) self.collectionview.selectitem(at: **indexpath**, animated:true…
Saira Nawaz
  • 710
  • 2
  • 10
  • 24
5
votes
2 answers

RxSwift access to indexPath.section

guys Im totally new in Rxswift, is there is a way to do this scenario in RxSwift ? What I got is this.. but problem is i dont have indexPath datasource.sectionModels .asObservable() .bindTo(tableView.rx.items) { tableView, row,…
Denis Kakačka
  • 697
  • 1
  • 8
  • 21
4
votes
5 answers

Get all indexPaths in a section

I need to reload the section excluding the header after I do some sort on my tableview data. That's to say I just want to reload all the rows in the section. But I don't find a easy way to make it after I search for a…
LF00
  • 27,015
  • 29
  • 156
  • 295
4
votes
1 answer

different types of cells in one collectionView

I have 4 different collectionViews in one controller, and in the first collectionView I want to have 3 different cells display. In the below code the app does not crash, but in the first indexPath.item of 0 only case 0: ("cellId") loads. It does not…
4
votes
1 answer

Get the indexPath of the relevant element in a loop

I'm working in a project in Swift 3.0 and I have a loop that would give me the state of an object (gives a boolean value in a an array sequence). My requirement is if the element state is "true" I wants to get the relevant index path of that, so…
danu
  • 1,079
  • 5
  • 16
  • 48
3
votes
3 answers

Get IndexPath of CollectionViewCell outside of Cell

First of all I am a newbie in swift, so be gentle. I have a problem fetching the indexPath of the cell outside of the cell. I want to get that index path to a function and use it to send the content to another view. The image was created…
Marian Petrisor
  • 262
  • 2
  • 19
3
votes
2 answers

Deleting Items out of collection view

I have currently created an array of images [1 - 8]. I have also created a collectionview that pulls images out of the imageArray and puts images in the imageview which is in the cell. Please note that the cell has one imageView in it and it takes…
Nivix
  • 171
  • 1
  • 1
  • 12
3
votes
2 answers

UICollectionView cellForItemAt indexPath is skipping row indexes in iOS 10

I have UICollectionView with horizontal scrolling and paging. When I scroll to next or previous page for the first time or change scrolling direction from left to right, value of indexPath.row in cellForItemAtIndexPath is changing by 3 not 1. Then…
Roman Siro
  • 226
  • 1
  • 11
2
votes
1 answer

How to identify first and last rows of each section | Swift

How can I identify the first and last rows of each section in a dynamic tableview and make a view inside the cell class hidden. For each first cell in each section I need to hide the topView, for each last row of each section, I need to hide the…
John
  • 965
  • 8
  • 16
2
votes
2 answers

Update Specific Button Image in UITableView Cell

I am trying to add an action to my "like" button. So that when the user taps the heart UIButton in a cell, the heart in the cell they tapped updates to a pink heart showing that they liked it. But instead it likes the heart they tapped and another…
user15709097
2
votes
1 answer

Passing Index of a selected row to another ViewController

I have a question concerning the passing of an index (myIndex) from a TableView to another ViewController. I have posted the code below. The good news: When I run the code, an Index is passed to the other Viewcontroller. The bad news: it is not the…
Ti Mi
  • 61
  • 3
2
votes
2 answers

Swift: Convert IndexSet to [IndexPath]

I want to get [IndexPath] from IndexSet in Swift 5. There is a question to convert NSIndexSet to Array in Objective-C. But there is no method enumerateIndexesUsingBlock in Swift 5. Who knows the way?
Emre Kayaoglu
  • 561
  • 2
  • 5
  • 19
1
2 3
11 12