logo
down
shadow

Switching between custom cells in Swift


Switching between custom cells in Swift

By : user2953541
Date : November 21 2020, 01:01 AM
I wish this help you Define a variable of UITableViewCell type and initialize it in both the if and the else branches, then use it as the return value:
code :
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{

    var retCell: UITableViewCell

    if istrue{
        var cell: CustomTableCell = self.tv.dequeueReusableCellWithIdentifier("cell") as CustomTableCell

        let data = myList[indexPath.row] as Model

        cell.customLabel.text = data.username
        cell.dateLabel.text = printDate(data.date)

        retCell = cell

    }else{
        var cell: CustomTableCell2 = self.tv.dequeueReusableCellWithIdentifier("cell") as CustomTableCell2

        let data = myList[indexPath.row] as Model

        cell.titleLabel.text = data.username
        cell.dateLabel2.text = printDate(data.date)

        retCell = cell
    }

    return retCell
}


Share : facebook icon twitter icon
Swift : Switching tableview cells in cellForRowAtIndexPath

Swift : Switching tableview cells in cellForRowAtIndexPath


By : Bhumi Shah
Date : March 29 2020, 07:55 AM
this one helps. How to switch btw cells in cellForRowAtIndexPath ?
code :
switch (IndexPath.row) 
  case 0:
        ///// add code here
  case 1:
       //////add code here
  default:
          //////add code here
}
Switching Custom Cells in UITableView in swift

Switching Custom Cells in UITableView in swift


By : mosharop
Date : March 29 2020, 07:55 AM
With these it helps You need to reload the affected row(s) in order for the cell type to change -
code :
var currentRow:Int?

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    var reloadRows=[NSIndexPath]()
    if self.currentRow != nil && indexPath.row != self.currentRow! {
        reloadRows.append(NSIndexPath(forRow: self.currentRow!, inSection: indexPath.section))
    }
    self.currentRow=indexPath.row
    reloadRows.append(NSIndexPath(forRow: self.currentRow!, inSection: indexPath.section))
    tableView.reloadRowsAtIndexPaths(reloadRows, withRowAnimation: UITableViewRowAnimation.Automatic)
    tableView.deselectRowAtIndexPath(indexPath, animated: true)
}
Smooth transition while switching cameras in custom camera swift + xcode

Smooth transition while switching cameras in custom camera swift + xcode


By : m.s.y
Date : March 29 2020, 07:55 AM
around this issue Call the loadCamera() function inside viewDidAppear instead of viewWillAppear
code :
override func viewDidAppear(animated: Bool) {
    super.viewDidAppear(true)
    loadCamera()
}
DispatchQueue.global(qos: .background).async {

    // perform ui updation and web related code
    // background thread

    DispatchQueue.main.async {
        // main thread
    }
}
Swift Switching To and FromTable ViewController Issue Using Custom Segue

Swift Switching To and FromTable ViewController Issue Using Custom Segue


By : Hotel
Date : March 29 2020, 07:55 AM
I hope this helps . The problem is that you are presenting the toViewcontroller each time a segue is performed. So the app presents table2 over table1, and then tries again to present table1 over table2 on the unwind.
Modify your custom segue to check - essentially - which direction you're going:
code :
class TableViewSegue: UIStoryboardSegue {

    override func perform() {
        scale()
    }

    func scale () {
        let toViewcontroller = self.destination
        let fromViewcontroller = self.source
        let containerView = fromViewcontroller.view.superview
        let originalCenter = fromViewcontroller.view.center
        toViewcontroller.view.transform = CGAffineTransform(scaleX: 0.05, y: 0.05)
        toViewcontroller.view.center = originalCenter

        containerView?.addSubview(toViewcontroller.view)

        let fromP = fromViewcontroller.presentingViewController

        UIView.animate(withDuration: 0.5, delay: 0, options: .curveEaseInOut, animations: {
            toViewcontroller.view.transform = CGAffineTransform.identity
        }, completion: { success in

            // if nil, we are presenting a new VC
            if fromP == nil {
                fromViewcontroller.present(toViewcontroller, animated: false, completion: nil)
            } else {
                fromViewcontroller.dismiss(animated: false, completion: nil)
            }

        })
    }

}
gradient keeps switching between cells in collection view in swift

gradient keeps switching between cells in collection view in swift


By : AliMadkour
Date : March 29 2020, 07:55 AM
Any of those help Reading your code in setGradientBackground(), you always init a new CAGradientLayer and insert it at the lowest position in your cell. Every time setGradientBackground() gets called again, the new gradient layer will be positioned below all other gradients you already inserted.
Try to get a already existing CAGradientLayer from sublayers and set the new colors.
code :
    var gradientLayer = CAGradientLayer()
    if let sublayers = layer.sublayers {
        for sublayer in sublayers {
            if let gLayer = sublayer as? CAGradientLayer {
                gradientLayer = gLayer
                break
            }
        }
    }
    gradientLayer.frame = bounds
    gradientLayer.colors = colours
    gradientLayer.locations = [0.0, 1.0]
    gradientLayer.startPoint = CGPoint(x: 1.0, y: 1.0)
    gradientLayer.endPoint = CGPoint(x: 0.0, y: 0.0)
    layer.insertSublayer(gradientLayer, at: 0)
if let existingLayer = (layer.sublayers?.compactMap { $0 as? CAGradientLayer })?.first {
    gradientLayer = existingLayer
}
Related Posts Related Posts :
  • Unclear about releasing CFDictionaryRef
  • CordovaError: Promise rejected with non-error: Error code 65
  • How to append NSMutable strings into a UILabel
  • CustomCell label value does not change
  • Display ad in iAd Bannerview iAd Network
  • Warning: "Could not get traitsetID for iPhone11,6" (Assets.xcassets)
  • Changing root view controller after iOS app has loaded.
  • SocketRocket and iOS certificate pinning
  • Draggable UIButton Snap To a Circle Path
  • Running FireBase in the background
  • resizing UIPopoverController to fit UITableController
  • UICollectionView Exception Crash
  • targeting iOS5 - will it work on iOS6 also?
  • FBLoginView get email
  • Scale UIImages height to UIImageView height
  • Creating a custom progress indicator in ios
  • NSRunLoop API difference
  • Is it possible to inject custom settings into my iOS application "Notifications" settings dialog?
  • UIAlertview not accepting string as message
  • Axis change of stackView giving layout error
  • How to use AVAssetResourceLoader?
  • How to write block definition using properties?
  • iOS connect/reconnect to Bluetooth device when using external-accessory and MFi
  • Saving XMPP Multi User chat messages through XMPP MessageArchiving in iOS
  • Deciding iOS version: pros and cons
  • iOS: Resigned app cannot access keychain through security API
  • How can I set To and Subject fields in an E-Mail being sent by UIDocumentInteractionController?
  • Updating uilabel in view controller underneath another
  • Maximum time Intervel for NSTimer
  • Delete Core Data Entry from Table View Controller
  • How to unload UIViewcontroller from memory?
  • Compressing UIImage as Far as Possible?
  • Optimizing workflow to update internally owned cocoapods dependencies?
  • Formatting an NSDate with Abbreviated Month/Day Names
  • I'm creating a quiz game with 4 answers and I want to add score
  • Tap Gesture to Hide Navigation Bar, Tab Bar, and Status Bar
  • FBSessionStateClosedLoginFailed when I am logged in through Settings
  • CGRect positioning according to center point
  • iOS: Update table view datasource with animations without core data
  • iOS : Where to start for AliPay integration?
  • Routing App Coverage File missing but not needed?
  • Drawing on a zoomable view
  • Append NSStrings and NSNumber to NSMutableArrays and make NSMutable dictionary
  • Terminating app due to uncaught exception 'NSRangeException' when calling dequeueReusableCellWithReuseIdentifier:forInde
  • Collision without physics (Cocos2D + Box2D iOS)
  • Creating a percentage based iOS layout
  • Update tableView row from AppDelegate Swift 4
  • Assigning return value of a class method to a variable error
  • how to display circular progress in delphi ios apps?
  • I can't figure how to fix this Expected identifier or '('
  • How to Test APIs in Swift 4?
  • Link error /Build/Products/Debug-iphonesimulator file not found
  • working with a very large JSON object in iOS
  • Turn off part of the iPhone Screen
  • Phonegap 3.0 app with facebook login using xCode
  • How to add interstitial admob ads to my ios project
  • adding tapku calendar to ios app
  • Add an alertcontroller in a global swift file?
  • Take square image with Cordova (Phonegap) Camera API?
  • Amazon S3 policy allowing only upload not overwrite
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org