ephread/Instructions

Framework is not woking with xib file it only accept viewcontroller in start function

getchec0 opened this issue · 1 comments

I am struck with this function for implementing for xib file

self.coachMarksController.start(in: .window(over: self))
It only accept the viewController not xib file in start(in: .) parameter. How to integrate this framework with .xib file

Here on these stackoverflow links are my tries to solve this issue but not successfull
link 1
link 2
Here is brief description of my attempts to fetch coordinates of element form xib.I have following IBoutlet from xib file

class CollectioCVCell: UICollectionViewCell {
    @IBOutlet weak var loMode : UIImageView!     
    @IBOutlet weak var tempe : UILabel!
    @IBOutlet weak var nam : UILabel!
    
    override func awakeFromNib() {
        super.awakeFromNib()
    }
}

Is it possible to access these IBOutlets(i.e., coordinates of them) from UIViewController.swift file where UICollectionView is made ?

How to access UICollectionViewCell elements from UICollectionView object in made in UIViewController.Provide me example code ?

Here is sample code that i am trying that is giving me null because in viewcontroller, viewdidload is called then awakeFromNib is called.so before awakeFromNib tr.loMode is nul. How i can get it coordinates in viewcontroller class?

var poi = UIView()
var poi2 = UIView()
var tr = CollectioCVCell()
class AppVC: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        poi2 = poifun() 
    }

    public func poifun() -> UIView {
        poi =  tr.loMode //error is =Thread 1: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value 
    }
}

How to remove this error that is given in comments and get xib element coordinates

Hi @getchec0, yes, it's possible. After attaching Instructions to a view controller (with start(in:)), you need to get a reference to the subview of your cell and create a CoachMark from it. For instance, for a given index path, something like what's below would create a default coach mark pointing to loMode.

func coachMarksController(
    _ coachMarksController: CoachMarksController,
    coachMarkAt index: Int
) -> CoachMark {
    let indexPath = // The relevant index path
    guard let cell = collectionView.cellForItem(at: indexPath) as? CollectioCVCell else {
        return CoachMark()
    }

    return coachMarksController.helper.makeCoachMark(for: cell.loMode)
}

Note, however, that you need to make sure the cell at indexPath is valid and is visible on screen, otherwise the behaviour is undefined. #249 may be helpful in that regard.

Have a look at the README and this example for further information about creating and displaying coach marks through the data source methods.