indexpath

UICollectionView cellForItemAt indexPath is skipping row indexes in iOS 10

萝らか妹 提交于 2020-02-01 06:20:31
问题 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. 回答1: Problem was with new prefetching feature of UICollectionView. Disabling of prefetching solved my problem. if #available(iOS 10.0, *)

Creating tableView inside tableView

五迷三道 提交于 2020-01-24 20:18:06
问题 I've created a tableView with prototype cells. Inside each of these prototype cells is another tableView with different prototype cells. I've linked this all together fine, but I'm having trouble modifying the innermost prototype cells. Here is why. Here is the relevant code: class ViewController: UIViewController, AVAudioRecorderDelegate, UITableViewDelegate, UITableViewDataSource { @IBOutlet weak var tableView: UITableView! override func viewDidLoad() { super.viewDidLoad() tableView

Get all indexPaths in a section

江枫思渺然 提交于 2020-01-13 03:54:13
问题 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 while. reloadSections(sectionIndex, with: .none) not works here, for it will reload the whole section including the header, footer and all the rows. So I need to use reloadRows(at: [IndexPath], with: UITableViewRowAnimation) instead. But how to get the whole indexPaths for the

How to get section of UITableView from inside a child UICollectionview

拜拜、爱过 提交于 2019-12-22 18:20:12
问题 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

How to check if IndexPath is valid?

时光怂恿深爱的人放手 提交于 2019-12-21 04:50:06
问题 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'" 回答1: Semantically, to consider an indexPath invalid , you need something to check for such as a table view or a collection view. Usually

How to display ads within a collection view

会有一股神秘感。 提交于 2019-12-21 04:10:53
问题 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,

Disclosure indicator to specific cell in static TableView in Swift

守給你的承諾、 提交于 2019-12-18 09:09:16
问题 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? 回答1:

Swift out of range… with tableView[indexPath]

感情迁移 提交于 2019-12-12 05:30:02
问题 I'm getting trouble with out of range error... The error occurs in cell.creditLabel.text = numOfDays[(indexPath as NSIndexPath).row] + "days" . And if I put tableView.reloadData() after cell.nameLabel.text = nameArray[(indexPath as NSIndexPath).row] then nothing shows up in the simulator... How can I fix this problem..? func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return self.nameArray.count } func tableView(_ tableView: UITableView, cellForRowAt

(Swift) fatal error: Index out of range

為{幸葍}努か 提交于 2019-12-12 03:52:36
问题 I have three arrays. One displays headers for each section on the tableView, one displays titles, and one has the links for each cell. When I run this code, I get: fatal error: Index out of range Here is what happens after it runs my code is: import UIKit class FirstViewController: UIViewController, UITableViewDataSource, UITableViewDelegate { var headers = ["Bein Sports", "Sky Sports", "Alkass", "Other"] var channels = [["Bein Sports 1","Bein Sports 2","Bein Sports 3","Bein Sports 4","Bein

presently delete core data item in uicollectionviewcell through tag

蹲街弑〆低调 提交于 2019-12-11 16:46:51
问题 I am trying to permanently delete a single element from a core data set. Right now the code below removes the core data item but it does not permanently delete it. Once the class is called again it shows up again like nothing happened. I want it permanently deleted. func loadData() { guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else { return } let managedContext = appDelegate.persistentContainer.viewContext let fetch = NSFetchRequest<Item>(entityName: "Item") do {