2015-06-19 6 views
14

Ho qualche codice dove ho 3 tasti e mi piacerebbe scoprire la vista padre di questi pulsanti quando si fa clicScopri la vista padre di un bottone cliccato in rapida

@IBAction func resizeButtonClicked(sender: UIButton) { 
    if(sender.isEqual(resizeButton)) { 
     //This is to convert to small square 
    } else if(sender.isEqual(maximizeButton)) { 
     //This is to convert to maximized view 
    } else if(sender.isEqual(closeButton)) { 
     //This is to close the view completely 

    } 
} 

Ora posso identificare il pulsante mittente, ma come faccio a identificare la vista in cui si trova questo pulsante?

Grazie

Nikhil

risposta

33

Si prega di provare la seguente

sender.superview 
1

ti non voglio creare una classe personalizzata e anche non si vuole usare accessibilityHin:

func performAction(_ sender : AnyObject?) 
{ 
    let cell = sender?.superview??.superviewOfClassType(UITableViewCell.self) as! UITableViewCell 
    let tbl = cell.superviewOfClassType(UITableView.self) as! UITableView 
    let indexPath = tbl.indexPath(for: cell) 
    let myData = myDataArray[indexPath.row] 
    ... 
} 
Problemi correlati