indexpath

Swift iOS -How can I pass a value Obtained Directly from a within TableViewCell's SubClass to the TableView's didSelectRow?

不羁的心 提交于 2019-12-11 08:54:14
问题 Before anyone suggests to pull the Firebase data from within the PlayerController's viewWillAppear, I already know how to do that and if I did it that way I know how to pass the data to the ScoreController. In this situation I need to pull the data directly from within the cell and somehow pass the data back from there. I have a tableView inside a PlayerController that displays the randomPower, name, and score of each player. Inside the tableView's cell I pull the name and score from Firebase

How to get section of UITableView from inside a child UICollectionview

人走茶凉 提交于 2019-12-06 08:09:51
I have a UITableView with a UICollectionView within each of its rows like the illustration below. source: https://ashfurrow.com/blog/putting-a-uicollectionview-in-a-uitableviewcell-in-swift/ The intention of my app is to display a character set of a language within each table view row. Each character is contained within a collection view cell of the collectionview within the corresponding row. The problem I am having is that the english character set is being displayed for every tableview row. This is because each collectionview only has one section and thus every collectionview uses the same

How to get indexpath from row index Swift

十年热恋 提交于 2019-12-06 03:02:36
问题 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 ,scrollPosition:UICollectionViewScrollPosition) Here it’s giving me error at bold position saying: cannot convert value of type Int to expected argument type 'IndexPath? I can understand this exception as indexpath is different in swift from

UICollectionView cellForItemAt indexPath is skipping row indexes in iOS 10

我们两清 提交于 2019-12-04 13:49:44
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 it works properly. CollectionView works without problems in iOS 9. The problem occurs just in iOS 10. Thanks. Problem was with new prefetching feature of UICollectionView. Disabling of prefetching solved my problem. if #available(iOS 10.0, *) {collectionView.isPrefetchingEnabled = false} Possible Case: Since you're using paging in your collectionView

How to check if IndexPath is valid?

╄→尐↘猪︶ㄣ 提交于 2019-12-03 15:27:28
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 check. Xcode8.3.1 compiler error: "Binary operator '!=' cannot be applied to operands of type 'IndexPath' and 'Int'" Semantically, to consider an indexPath invalid , you need something to check for such as a table view or a collection view. Usually you can consider an indexPath invalid if it represents a row where there is no corresponding data in the

How to display ads within a collection view

非 Y 不嫁゛ 提交于 2019-12-03 12:25:57
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 "longDataArray") that I would get from the web. I could manage to add some banner ads to my collectionView but the problem is that it's breaking the order of my longDataArray. For example, just for testing when I'm adding an ad banner at indexPath 6, then the ad banner correctly shows up at indexPath 6, and I'm able to manage the width change for the cell

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

て烟熏妆下的殇ゞ 提交于 2019-11-30 06:37:50
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 this, it worked, but the extension in the answer below is much more readable, and sensible, and achieves the goal of one that's exactly as the pseudo code. an array of "positions" is created: [3, 5, 8, 12] let sorted = positions.sorted(by: { $1 < $0 }) for index in sorted { myArray.remove(at: index) } It's possible if the indexes are continuous using

Disclosure indicator to specific cell in static TableView in Swift

假如想象 提交于 2019-11-29 15:54:53
I created a static TableView and I would like to add or remove a disclosure indicator depending if we are consulting our own account or a guest account. This is what I would like : let index = IndexPath(row: 4, section: 0) let cell = tableView.cellForRow(at: index) if currentUser { cell.accessoryType = .none //cell.backgroundColor = UIColor.red } I tried to put it in the viewDidLoad function but it didn't work. I tried cellForRowAt indexPath also and same result. How could I do that? Your are working with static cells so cellForRow will not get called. Instead, simply drag connect your cell

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

ぐ巨炮叔叔 提交于 2019-11-29 06:17:11
问题 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 this, it worked, but the extension in the answer below is much more readable, and sensible, and achieves the goal of one that's exactly as the pseudo code. an array of "positions" is created: [3, 5, 8, 12] let sorted = positions.sorted(by: { $1 < $0