How to improve performance of UICollectionView with custom cell sizes?
You don't need to reload UICollectionView
by calling reloadData
, instead you can use:
[self.collectionView reloadItemsAtIndexPaths:[NSArray arrayWithObject:indexPath]];
Here, indexPath
is the NSIndexPath
object for the corresponding UICollectionViewCell
object
that you want to update.
UICollectionview Scrolling choppy when loading cells
So anybody having scrolling issues should do this
add these 2 lines after your dequeue
cell.layer.shouldRasterize = YES;
cell.layer.rasterizationScale = [UIScreen mainScreen].scale;
How to loop invisible cells in UICollectionView
You don't have to loop invisible cells. Keep using datasource approach. What you are looking for is the way to map textFields to the datasource.
There are many solutions, but the easy one is using Dictionary
.
Here's the code for UITableViewDataSource
but you can apply it to UICollectionViewDataSource
class MyCustomCell: UITableViewCell{
@IBOutlet weak var textField: UITextField!
}
class ViewController: UIViewController{
// datasource
var textSections = [ [ "one" , "two" , "three"] , [ "1" , "2" , "3"] ]
// textField to datasource mapping
var textFieldMap: [UITextField:NSIndexPath] = [:]
// MARK: - Action
func textChanged(sender: UITextField){
guard let indexPath = textFieldMap[sender] else { return }
guard let textFieldText = sender.text else { return }
textSections[indexPath.section][indexPath.row] = textFieldText
}
@IBAction func submitButtonTapped(){
// validate texts here
for textRow in textSections{
for text in textRow{
if text.characters.count <= 0{
return print("length must be > 0.")
}
}
}
performSegueWithIdentifier("goToNextPage", sender: self)
}
}
extension ViewController: UITableViewDataSource{
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("identifer") as! MyCustomCell
// set value corresponds to your datasource
cell.textField.text = textSections[indexPath.section][indexPath.row]
// set mapping
textFieldMap[cell.textField] = indexPath
// add action-target to textfield
cell.textField.addTarget(self, action: "textChanged:", forControlEvents: .EditingChanged)
return cell
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return textSections[section].count
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return textSections.count
}
}
UICollectionView & AVPlayer Performance
First I want to say it's a bit crazy to see several players in action at the same time: it's a heavy task of rendering anyway.
As far as I know, simply scaling/re-framing the video to smaller size doesn't make it less content to render: if you have a 100x100 picture to render and you render it in a frame of 10x10, it still consumes the same amount of memory as the original picture would consume; same thing goes for videos. So, try to make your video assets having similar resolution as the frame where you would present them.
UICollectionView inside UICollectionViewCell
I managed to do this in another way. Instead of embed a UICollectionView inside another, I iterated through the array of elements and created subviews above the label.
if let item = info["PRODUTOSITENS"] as? [[String:Any]] {
for produto in item {
// All the business logic
let DynamicView = UIView(frame: CGRect(x:Double(cell.status.frame.origin.x), y:y, width:Double(collectionView.frame.size.width - 20.0), height:80.0))
cell.addSubview(DynamicView)
}
}
Related Topics
Why Are My Variables Empty When I Cast Them in My iOS Application
Uitableviewcell Separator Disappearing in iOS7
How to Change "Initwithnibname" in Storyboard
Xcode 8 Beta - Convert to Current Swift Syntax Failed: Could Not Find Test Host
How to Write Init Methods of a Uiviewcontroller in Swift
How to Turn Flashlight on and Off in Swift
How to Get the Custom Overlay for Uiimagepicker Camera to Be Full Screen in iOS 7
Setting an Nsmanagedobject Relationship in Swift
Transparent Uinavigationbar in Swift
How to Intercept Push Notifications for Another App
Is There a Public API for Card View UI That Can Be Seen Across iOS 10
iOS App Submission and Beta Review Process
Presentviewcontroller and Displaying Navigation Bar
How to Change Navigation Bar Color in iOS 7 or 6
How to Add Text Input in Alertview of iOS 8
How to Get iOS Appstorereceipturl into Base 64 Encoded String