2016-04-13 33 views
1

学校の場合、私はホロコーストについてのアプリを作っています。 detailViewControllerにキャンプに関する情報を表示する必要がありますが、機能していません。私は変数の "名前"の値にアクセスできます(私の用語が間違っていれば申し訳ありません)。他の投稿はSwiftには載っていない、または私の特定の問題に関連していないので、解決策を見つけることができません。ここタイプ 'AnyObject'の値にメンバーがありません '

は、変数の型を作成するクラスからのコードである:

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?)  { 
    if segue.identifier == "showDetail" { 
     if let indexPath = self.tableView.indexPathForSelectedRow { 
      let deathCampNewObject = deathCampArray[indexPath.row] 
      let countryDeathNewObject = countryArray[indexPath.row] 
      let controller = (segue.destinationViewController as! UINavigationController).topViewController as! DetailViewController 
      controller.detailItemDeath = deathCampNewObject 
      controller.detailItemCountry = countryDeathNewObject 
      controller.navigationItem.leftBarButtonItem = self.splitViewController?.displayModeButtonItem() 
      controller.navigationItem.leftItemsSupplementBackButton = true 
     } 
    } 
} 

提案に応答して:ここ

class DeathCamp: NSObject { 

var name:String = "" 
var locationCountry:String = "" 
var jewishDeathCount:Int = 0 
init(name:String, locationCountry:String, jewishDeathCount:Int){ 
    self.name = name 
    self.locationCountry = locationCountry 
    self.jewishDeathCount = jewishDeathCount 
} 



} 

は、詳細項目がアレイに設定されているコードでありますコメントから、DetailViewControllerの全コードは次のとおりです。

import UIKit 

class DetailViewController: UIViewController { 

    @IBOutlet weak var detailDescriptionLabel: UILabel! 

@IBOutlet var percentageJewsKilled: UILabel! 
@IBOutlet var jewsKilled: UILabel! 
let masterViewController = MasterViewController() 

var detailItemDeath: AnyObject? { 
    didSet { 
     // Update the view. 
     self.configureView() 
    } 
} 
var detailItemCountry: AnyObject? { 
    didSet { 
     // Update the view. 
     self.configureView() 

    } 
} 

func configureView() { 
    // Update the user interface for the detail item. 
    if let detail = self.detailItemDeath { 
     if let label = self.detailDescriptionLabel { 
      label.text = detailItemDeath?.name 
     } 
     if let label = self.jewsKilled { 
      label.text = "\(detailItemDeath?.jewishDeathCount)" 
     } 
    } 
} 
override func viewDidLoad() { 
    super.viewDidLoad() 
    // Do any additional setup after loading the view, typically from a nib. 
    self.configureView() 
} 

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


} 
+1

すべてのコードがなくても、何を呼び出すのかを理解することは難しいです。 'configureView'はどのクラスに属していますか?それを何と呼びますか? 'DetailViewController'のコードを投稿してください。 – ryantxr

答えて

1

変更

if let detail = self.detailItemDeath

に上記

if let detail = self.detailItemDeath as? DeathCamp

コードタイプDeathCampのオブジェクトにdetailItemDeathキャストを試みます。あなたは既に、オプションのチェーンが冗長ので、誤っている、if let構文でdetailItemDeathのアンラップをしようとしました

detailItemDeath.name

detailItemDeath?.name

を変更。

そして、私はこれを逃したとは思わない、detailItemDeathの名前をdetailItemDeath.nameからdetailに変更してください!

+0

私はそのコード行を変更しましたが、まだそれは私に同じエラーを与えています。 –

+0

@BenA:私の答えを更新しました。 –

+0

素早い返答をありがとう。私があなたが提案したことをするとき、私は「AnyObjectのオプション型の値」を取得します。アンラップされていない;あなたは '!'または '?'? " –

関連する問題