Próbuję zaimplementować accessoryButtonTappedForRowWithIndexPath:
w Swift 2 na UITableViewController
.Implementowanie akcesoriumButtonTappedForRowWithIndexPath: w Swift 2
Jak wyjaśniono poniżej, myślę, że brakuje mi czegoś, gdy tworzę disclosureIndicator
, ale nie wiem co. Jest pobierany z kodu, ale moja akcja docelowa nie zostaje wywołana. UGH!
Aby to zrobić programowo, muszę wiedzieć, że muszę dodać wskaźnik detailDisclosure pod numerem cellForRowAtIndexPath
, zanim zostanie zwrócony mój cell
. Robię to w następujący sposób:
// Create disclosure indicator button in the cell
let disclosureIndicatorButton = UIButton(type: UIButtonType.DetailDisclosure)
disclosureIndicatorButton.addTarget(self, action: "disclosureIndicatorPressed:event:", forControlEvents: UIControlEvents.TouchUpInside)
customCell.accessoryType = .DisclosureIndicator
W moim kodzie detailDisclosure Chevron zostanie sporządzony, ale metoda działania cel I przypisany do niego nie zostanie wywołana.
Potem trzeba utworzyć uchwyt dla przycisku, gdy jest wciśnięty:
func disclosureIndicatorPressed(sender: UIButton, event: UIControlEvents) {
print("disclosure button pressed")
// convert touches to CGPoint, then determine indexPath
// if indexPath != nil, then call accessoryButtonTappedForRowWithIndexPath
}
Wreszcie accessoryButtonTappedForRowWithIndexPath
zawiera kod do wykonania segue, co mogę zrobić. czego mi brakuje?
To był mój problem. "DisclosureIndicator" to po prostu cukierek do oczu, nie robi nic innego, jak tylko się rysuje. 'DetailDisclosureButton' faktycznie może mieć powiązane z nim działania. Dziękuję, że mnie wyprostowałeś. – Adrian
Cieszę się, że pomogło! Twoje zdrowie :)! – Abhinav