没有名为的成员

时间:2014-11-11 21:23:10

标签: ios xcode swift tableview member

我通过传递数据创建简单的应用,但我不知道如何修复它。在此代码中。

       (segue.destinationViewController as DetailViewController).url = (self.arrayOfPrograms.objectAtIndex(indexPath.row) as Program).url

我有这个错误。!

"' DetailViewController'没有名为' url'"这是我的代码

 class Program: NSObject {
var name: NSString
var url: NSString

init(name:NSString, url:NSString) {
    self.name = name
    self.url = url
}

}

的ViewController

class ViewController: UITableViewController, UISearchBarDelegate, UISearchDisplayDelegate, ADBannerViewDelegate {

    var arrayOfPrograms: NSArray = []
    @IBOutlet weak var ViewController: UITableView?
    var color = UIColor.whiteColor()
    var sideMenu : SideMenu?
    var bannerView:ADBannerView?

    override func viewDidLoad() {
        //Písmo v Navigation bare.
        self.navigationController?.navigationBar.titleTextAttributes =
            [NSFontAttributeName: UIFont(name: "HelveticaNeue-Light", size: 20)!,
                NSForegroundColorAttributeName: UIColor.whiteColor()]

        super.viewDidLoad()
        self.navigationController?.navigationBar.tintColor = color
        self.canDisplayBannerAds = true
        self.bannerView?.delegate = self
        self.bannerView?.hidden = true

        /*
        sideMenu = SideMenu(sourceView: self.view, menuData: ["Slovenské Televízie", "České televízie", "Nemecké televízie"])
        sideMenu!.delegate = self
        */
        navigationController?.hidesBarsOnSwipe = true  // Zmiznutie Navigation baru na pohyb prsta nahor.

        self.arrayOfPrograms = [Program(name: "Markíza", url: "http://1.com")]

    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
            return self.arrayOfPrograms.count
    }

    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = self.tableView.dequeueReusableCellWithIdentifier("cell") as UITableViewCell

        let imageName = UIImage(named: (self.arrayOfPrograms.objectAtIndex(indexPath.row) as Program).name)

        cell.imageView.image = imageName
        cell.textLabel.text = (self.arrayOfPrograms.objectAtIndex(indexPath.row) as Program).name
        cell.textLabel.font = UIFont(name: "HelveticaNeue-Bold", size: 15)
        cell.textLabel.textColor = UIColor(red: 101.0/255.0, green: 112.0/255.0, blue: 122.0/255.0, alpha: 1.0);
        cell.textLabel.highlightedTextColor = UIColor(red: 255.0/255.0, green: 255.0/255.0, blue: 255.0/255.0, alpha: 1.0);
        cell.detailTextLabel?.text = "Kategória  ★★★☆☆"
        cell.detailTextLabel?.font = UIFont(name: "HelveticaNeue-Light", size: 10)
        cell.detailTextLabel?.textColor = UIColor(red: 101.0/255.0, green: 112.0/255.0, blue: 122.0/255.0, alpha: 1.0);
        cell.detailTextLabel?.highlightedTextColor = UIColor(red: 255.0/255.0, green: 255.0/255.0, blue: 255.0/255.0, alpha: 1.0);
        cell.accessoryType = UITableViewCellAccessoryType.DisclosureIndicator

        var myBackView=UIView(frame:cell.frame)
        myBackView.backgroundColor = UIColor(red: 81.0/255.0, green: 196.0/255.0, blue: 212.0/255.0, alpha: 1.0);
        cell.selectedBackgroundView = myBackView;
        return cell
    }

    override func supportedInterfaceOrientations() -> Int {
        return Int(UIInterfaceOrientationMask.Portrait.rawValue)
    }
    /*
    func sideMenuDidSelectItemAtIndex(index: Int) {
        sideMenu?.toggleMenu()
        if index == 1 {
            let vc = ViewController(nibName: "ViewController", bundle: nil)
            navigationController?.pushViewController(vc, animated: true)
        }
        */

    func bannerViewDidLoadAd(banner: ADBannerView!) {
        self.bannerView?.hidden = false
    }

    func bannerViewActionShouldBegin(banner: ADBannerView!, willLeaveApplication willLeave: Bool) -> Bool {
        return willLeave
    }

    func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error: NSError!) {
        self.bannerView?.hidden = true
    }

    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
        var indexPath: NSIndexPath = self.tableView?.indexPathForSelectedRow() as NSIndexPath!
        var destinationViewController: DetailViewController
        (segue.destinationViewController as DetailViewController).url = (self.arrayOfPrograms.objectAtIndex(indexPath.row) as Program).url
    }
}

我无法解决这个问题。

如果我这样做:

class DetailViewController {
    var url: NSString

    init(url:NSString) {
        self.url = url
    }
}

我将获得' DetailViewController'

的无效重新声明

DetailViewController

import UIKit
import MediaPlayer

class DetailViewController: UIViewController, ADBannerViewDelegate{

var moviePlayer:MPMoviePlayerController!
var color = UIColor.whiteColor()


    override func viewDidLoad() {
        super.viewDidLoad()

        self.navigationController?.navigationBar.titleTextAttributes =
            [NSFontAttributeName: UIFont(name: "HelveticaNeue-Light", size: 20)!,
            NSForegroundColorAttributeName: UIColor.whiteColor()]
        self.navigationController?.navigationBar.tintColor = color
       self.navigationItem.title = (self.arrayOfPrograms.objectAtIndex as Program).name

       var url = NSURL(self.arrayOfPrograms.objectAtIndex as Program).url
        moviePlayer = MPMoviePlayerController(contentURL: url)

        moviePlayer.view.frame = CGRect(x: 0, y: 0, width: self.view.frame.size.width, height: self.view.frame.size.height)
        moviePlayer.view.sizeToFit()
        self.view.addSubview(moviePlayer.view)
        moviePlayer.fullscreen = true
        moviePlayer.controlStyle = MPMovieControlStyle.Embedded
    }

    override func supportedInterfaceOrientations() -> Int {
        return Int(UIInterfaceOrientationMask.Portrait.rawValue)
    }

1 个答案:

答案 0 :(得分:0)

如果将此作为编译错误,则DetailViewController不会定义名为url的属性。 如果在执行期间出现错误,则destinationViewController不是DetailViewController。设置一个断点并检查它到底是什么类型。