В моем приложении iOS 8 у меня есть пользовательский ViewController, который я представляю как Popover. Этот ViewController имеет делегат, который получает и отправляет родительский ViewController, щелкнув индекс во всплывающем окне. Проблема в том, что я не могу уволить этого Поповера после selectRow.Отклонить Popover ViewController от Tableviewcell в Swift
Вот код:
Это метод, который я называю, когда я хочу, чтобы показать мою Popup.
@IBAction func registerButtonAction(sender: UIButton) {
popup = self.storyboard!.instantiateViewControllerWithIdentifier("PopupViewController") as? PopupViewController
popup!.modalPresentationStyle = .Popover
popup!.preferredContentSize = CGSizeMake(100, 120)
let popoverMenuViewController = popup!.popoverPresentationController
popoverMenuViewController?.permittedArrowDirections = .Up
popoverMenuViewController?.delegate = self
popoverMenuViewController?.sourceView = sender
popoverMenuViewController?.sourceRect = CGRect(
x: sender.frame.size.width/2,
y: sender.frame.size.height/2,
width: 1,
height: 1)
popup!.delegate = self
presentViewController(
popup!,
animated: true,
completion: nil)
}
Вот PopupViewController код:
protocol PopupViewControllerDelegate
{
func rowClickedAtIndex(var index : Int)
}
class PopupViewController: MainViewController {
var delegate : PopupViewControllerDelegate?
@IBOutlet weak var tableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
extension PopupViewController:UITableViewDelegate{
func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
var cell:PopupTableViewCell? = tableView.dequeueReusableCellWithIdentifier("PopupTableViewCell") as? PopupTableViewCell
if cell == nil {
cell = PopupTableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "PopupTableViewCell")
}
return cell
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
if (self.delegate != nil)
{
self.delegate!.rowClickedAtIndex(indexPath.row)
self.dismissViewControllerAnimated(true, completion: nil)
}
}
func numberOfSectionsInTableView(tableView: UITableView?) -> Int {
return 1
}
func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int{
return 2
}
}
Спасибо.
Я попытался здесь: расширение WelcomeViewController: PopupViewControllerDelegate { функ rowClickedAtIndex (индекс: Int) { всплывающее окно .dismissViewControllerAnimated? (Правда, завершение: ноль) Println (индекс) }} Но не работает. Он проходит в этом методе, потому что он печатает индекс, но он не отклоняет его. – Bellots
Похоже, что 'popup' все еще пытается выполнить вызов. 'WelcomeViewController' должен выполнить его. 'rejectViewControllerAnimated (true, completion: noil)' – Frankie
Что мне делать по вашему мнению? – Bellots