2017-08-02 3 views
0

私はSwiftのテーブルビューで動作するtodoリストアプリを開発しています。テーブルビューにはtitleLabelOutletというUILabelがあります。私は、アプリケーションを構築していたときに私はエラーが出てくるThe titleLabelOutlet outlet from the FirstViewController to the UILabel is invalid. Outlets cannot be connected to repeating content.これまでにこのエラーを受け取ったことはありません。どうすれば修正できますか?ラベルは、セル 内部にあり、デリゲートでcrllfor行にあなたがその ようなあなたの店舗を取得する必要がありますので、あなたの店ではなくのViewControllerのセルクラスにする必要がありますVCからUILabelへのコンセントが無効です。アウトレットをリピートコンテンツに接続することはできません

import UIKit 

var phoneNumberList = [String]() 
var titleFieldList = [String]() 
class FirstViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { 

@IBOutlet weak var titleLabelOutlet: UILabel! 
@IBOutlet weak var phoneNumberLabelOutlet: UILabel! 

@IBOutlet weak var myTableView: UITableView! 

public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int 
{ 
    return (phoneNumberList.count) 
} 

public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell 
{ 
    let cell = UITableViewCell(style: UITableViewCellStyle.default, reuseIdentifier: "cell") 
    phoneNumberLabelOutlet.text = phoneNumberList[indexPath.row] 
    titleLabelOutlet.text = titleFieldList[indexPath.row] 

    return(cell) 
} 

func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) 
{ 
    if editingStyle == UITableViewCellEditingStyle.delete 
    { 
     phoneNumberList.remove(at: indexPath.row) 
     titleFieldList.remove(at: indexPath.row) 
     myTableView.reloadData() 
    } 
} 

override func viewDidAppear(_ animated: Bool) { 
    myTableView.reloadData() 
} 

override func viewDidLoad() { 
    super.viewDidLoad() 
    // Do any additional setup after loading the view, typically from a nib. 
} 

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


} 

error image

+1

可能な重複ができないため、今あなたがラベルの値を設定することができます繰り返しコンテンツiOSに接続](https://stackoverflow.com/questions/26561461/outlets-cannot-be-connected-to-repeating-content-ios) – dan

答えて

0

`てみましょう:これは私のコードですセル= tableView.dequeueReusableCell(withReuseIdentifier:cellIdentifier」のため、:indexPath)!TableViewCellClassとして

cell.lbloutlet.text = "テキスト" リターンセル

`

0

CustomTableCellサブクラスのUITableViewCellを作成します。

は、細胞内のラベルを持つとCustomTableCellクラスでtitleLabelOutlet& phoneNumberLabelOutlet に接続します。

customTableCellを使用すると、cellForRowAtIndex関数のUITableViewCellが使用されます。 [アウトレットの

cell.phoneNumberLabelOutlet.text = phoneNumberList [indexPath.row] cell.titleLabelOutlet.text = titleFieldList [indexPath.row]

+0

私はこれをUITableViewCellファイルで行うと動作しません –

関連する問題