提问人:user16780334 提问时间:6/29/2021 最后编辑:user16780334 更新时间:6/30/2021 访问量:188
如何遍历MFMessageViewController的视图层次结构?
How to traverse through the view hierarchy of MFMessageViewController?
问:
我想遍历MFMessageComposerController的视图层次结构,以便可以获取填充消息的UITextField实例。这是我在 Swift 中为呈现 MFMessageController 所做的代码。如何遍历其层次结构?
代码:
@IBAction func sendSmsClick(_ sender: AnyObject) {
guard MFMessageComposeViewController.canSendText() else {
return
}
let messageVC = MFMessageComposeViewController()
messageVC.view.endEditing(true)
messageVC.body = "Enter a message";
messageVC.recipients = ["Enter tel-nr"]
messageVC.messageComposeDelegate = self;
NSLog("Subviews %@", messageVC.view.subviews);
// self.view.endEditing(true)
self.present(messageVC, animated: false) {
}
}
func messageComposeViewController(_ controller: MFMessageComposeViewController, didFinishWith result: MessageComposeResult) {
switch (result.rawValue) {
case MessageComposeResult.cancelled.rawValue:
print("Message was cancelled")
self.dismiss(animated: true, completion: nil)
case MessageComposeResult.failed.rawValue:
print("Message failed")
self.dismiss(animated: true, completion: nil)
case MessageComposeResult.sent.rawValue:
print("Message was sent")
self.dismiss(animated: true, completion: nil)
default:
break;
}
}
谁能告诉如何遍历MFMessageViewController的视图层次结构?
NSLOG 的结果
我的议程是模仿这个应用程序中显示的内容。查找文本字段并禁用编辑 .来自Appstore的应用程序:
答: 暂无答案
评论
NSLog("Subviews %@", messageVC.view.subviews);
它至少有效吗?任何输出?我可能会打电话强制加载。此外,XCode 的 Debug View Hierarchy 也可能有所帮助。但是,由于它是私人的,我不会建议这样做。loadView
NSLog("Subviews %@", messageVC.view.subviews);
NSArray
UIView
subview