질문을 올바르게 이해했는지 모르겠다. 다음은 귀하의 질문에 대해 생각한 것입니다 :
MenuViewController는 메뉴 목록 인 셀의 셀 목록을 선택하면 MainViewController의 webview가 링크 URL을로드하지만이 URL은 MenuViewController에 배치됩니다. 이 질문 인 경우
, 당신은이 솔루션으로 해결할 수 있습니다
MainViewController 알림 관찰자를 추가하고 MenuViewController 알림을
// MainViewController
class ViewController: UIViewController {
let webView = UIWebView()
override func viewDidLoad() {
super.viewDidLoad()
webView.frame = self.view.bounds
self.view.addSubview(webView)
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(ViewController.handleNotification(_:)), name: "OpenURL", object: nil)
}
func handleNotification(notification:NSNotification) {
if let url = notification.userInfo?["url"] {
webView.loadRequest(NSURLRequest(URL: url as! NSURL))
}
}
}
// MenuViewController
class MenuViewController: UIViewController, UITableViewDelegate {
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let userInfo = ["url" : your_url]
NSNotificationCenter.defaultCenter().postNotificationName("OpenURL", object: nil, userInfo: userInfo)
}
}
UPDATE 게시 방법 :
을 UITableView 사용
class MenuViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
let tableView = UITableView(frame: CGRectZero, style: .Plain)
let urls = ["https://google.com", "https://youtube.com", "http://stackoverflow.com/"]
let cellIdentifier = "CellIdentifier"
override func viewDidLoad() {
super.viewDidLoad()
tableView.delegate = self
tableView.dataSource = self
tableView.frame = view.bounds
tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: cellIdentifier)
view.addSubview(tableView)
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return urls.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath)
cell.textLabel?.text = urls[indexPath.row]
return cell
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let url = NSURL(string: urls[indexPath.row])!
let userInfo = ["url" : url]
NSNotificationCenter.defaultCenter().postNotificationName("OpenURL", object: nil, userInfo: userInfo)
}
}
의 정보를 처리하는 방법에 대해 설명합니다. 사용중인 프레임 워크와 설명서의 위치는 무엇입니까? Delegate-Protocols 또는 알림을 사용하여 가능해야합니다. – FelixSFD
@FelixSFD 빠른 답장을 보내 주셔서 감사합니다. 내가 사용하고있는 사이드 메뉴 프레임 워크에 대한 링크를 포함하도록 질문을 편집했습니다. –