首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >覆盖漏斗viewDidLoad

覆盖漏斗viewDidLoad
EN

Stack Overflow用户
提问于 2014-12-01 17:11:38
回答 1查看 6.7K关注 0票数 1

,我怎样才能解决这个问题?告诉我viewDidLoad被声明了两次,但是我可以统一整个过程??

代码语言:javascript
复制
import UIKit
import MessageUI
import CoreData
import MediaPlayer
import AVFoundation

class ViewController: UIViewController, UISearchBarDelegate, MFMailComposeViewControllerDelegate, MPMediaPickerControllerDelegate, AVAudioPlayerDelegate {
        override func viewDidLoad() {
        super.viewDidLoad()

        title = "Media picker..."

        buttonPickAndPlay = UIButton.buttonWithType(.System) as? UIButton

        if let pickAndPlay = buttonPickAndPlay{
            pickAndPlay.frame = CGRect(x: 0, y: 0, width: 200, height: 37)
            pickAndPlay.center = CGPoint(x: view.center.x, y: view.center.y - 50)
            pickAndPlay.setTitle("Pick and Play", forState: .Normal)
            pickAndPlay.addTarget(self,
                action: "displayMediaPickerAndPlayItem",
                forControlEvents: .TouchUpInside)
            view.addSubview(pickAndPlay)
        }

        buttonStopPlaying = UIButton.buttonWithType(.System) as? UIButton

        if let stopPlaying = buttonStopPlaying{
            stopPlaying.frame = CGRect(x: 0, y: 0, width: 200, height: 37)
            stopPlaying.center = CGPoint(x: view.center.x, y: view.center.y + 50)
            stopPlaying.setTitle("Stop Playing", forState: .Normal)
            stopPlaying.addTarget(self,
                action: "stopPlayingAudio",
                forControlEvents: .TouchUpInside)
            view.addSubview(stopPlaying)
        }
    }

    @IBOutlet weak var Subject: UITextField!


    @IBOutlet weak var Body: UITextView!

    @IBOutlet weak var searchBar: UISearchBar!

    @IBOutlet weak var webView: UIWebView!


    override func viewDidLoad() {
        super.viewDidLoad()


        searchBar?.delegate = self

        let url = NSURL(string: "http://www.google.com")
        let request = NSURLRequest(URL: url!)

        webView?.scalesPageToFit = true
        webView?.loadRequest(request)

    }

}

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-12-01 17:15:01

只需将两个中的一个移动到另一个,除了这一行super.viewDidLoad()之外,它必须被调用一次:

代码语言:javascript
复制
override func viewDidLoad() {
    super.viewDidLoad()

    title = "Media picker..."

    buttonPickAndPlay = UIButton.buttonWithType(.System) as? UIButton

    if let pickAndPlay = buttonPickAndPlay{
        pickAndPlay.frame = CGRect(x: 0, y: 0, width: 200, height: 37)
        pickAndPlay.center = CGPoint(x: view.center.x, y: view.center.y - 50)
        pickAndPlay.setTitle("Pick and Play", forState: .Normal)
        pickAndPlay.addTarget(self,
            action: "displayMediaPickerAndPlayItem",
            forControlEvents: .TouchUpInside)
        view.addSubview(pickAndPlay)
    }

    buttonStopPlaying = UIButton.buttonWithType(.System) as? UIButton

    if let stopPlaying = buttonStopPlaying{
        stopPlaying.frame = CGRect(x: 0, y: 0, width: 200, height: 37)
        stopPlaying.center = CGPoint(x: view.center.x, y: view.center.y + 50)
        stopPlaying.setTitle("Stop Playing", forState: .Normal)
        stopPlaying.addTarget(self,
            action: "stopPlayingAudio",
            forControlEvents: .TouchUpInside)
        view.addSubview(stopPlaying)
    }

    ///

    searchBar?.delegate = self

    let url = NSURL(string: "http://www.google.com")
    let request = NSURLRequest(URL: url!)

    webView?.scalesPageToFit = true
    webView?.loadRequest(request)
}

只是好奇,你为什么要声明两次这个方法?

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27233586

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档