未从NSObject类调用Swift委托函数(不是2 ViewController方案)

时间:2018-10-05 03:41:04

标签: swift delegates

对不起,是的,这是另一个需要Swift协议帮助的问题。过去在两个使用prepare(ForSegue ...)标准的VC之间使用它们就好了。但是,我的情况不包括2个VC。

在我的应用中,我有一个视图控制器(称为VC A),它具有一个滑出设置菜单,其中包括一个用于更改组图像的选项。设置菜单的功能运行正常,除非VC A上显示的imageView没有更新(除非用户离开VC并返回)。设置菜单选项完成后,VC A上的委托功能未执行。

预先感谢您的帮助。

我有一个Protocols.swift文件,用于我正在使用的各种委托协议。这种情况的协议:

protocol UpdateGroupImageviewDelegate: class {

    func updateGroupImageview()

}

滑出设置菜单的相关代码:

class GroupSettingsLauncher: NSObject, UICollectionViewDelegateFlowLayout, UICollectionViewDelegate, UICollectionViewDataSource, UIImagePickerControllerDelegate, UINavigationControllerDelegate {

weak var delegate: UpdateGroupImageviewDelegate?

    // rest of the settings menu code, including one that executes the imagePicker

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {

    // do the normal imagePicker stuff to get the selected image
    // store the image, etc.

    // call delegate method to update group image on chat screen
    print("ABOUT TO CALL DELEGATE FOR UPATEGROUPIMAGEVIEW")  // this prints correctly

    self.delegate?.updateGroupImageview()

     }

}

viewController A中的代码:

class GroupChatViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, UITextViewDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate, UpdateGroupImageviewDelegate {

// Delegate Variable
var updateGroupImageviewDelegate: GroupSettingsLauncher?

override func viewDidLoad() {
        super.viewDidLoad()

        // Set this VC as the delegate for updating the group Imageview
        updateGroupImageviewDelegate?.delegate = self

       // rest of code

}

func updateGroupImageview() {
        print("*** updateGroupImageview has been called!") // This is not printing

    }

}

0 个答案:

没有答案