2016-03-07 55 views
3

嗯,我创建的tableview和它里面的tableview与厦门国际银行文件里面创建tableviewcell的tableview

现在我想创建XIB文件里面的tableview细胞,主要的问题是,你无法在它的内部产生细胞定义该小区标识符

我不断收到此错误

“无法离队与标识符AutoCompleteRowIdentifier细胞 - 必须注册一个笔尖或标识类或连接 原型CE LL在故事板”

这是我的代码

import UIKit 

class TableViewCell2: UITableViewCell, UITableViewDelegate, UITableViewDataSource, UITextFieldDelegate { 

@IBOutlet weak var textField: UITextField! 

@IBOutlet weak var autocompleteTableView: UITableView! 

var pastUrls = ["Men", "Women", "Cats", "Dogs", "Children"] 
var autocompleteUrls = [String]() 


func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool 
{ 
    autocompleteTableView.hidden = false 
    let substring = (textField.text! as NSString).stringByReplacingCharactersInRange(range, withString: string) 

    searchAutocompleteEntriesWithSubstring(substring) 
    return true  // not sure about this - could be false 
} 

func searchAutocompleteEntriesWithSubstring(substring: String) 
{ 
    autocompleteUrls.removeAll(keepCapacity: false) 

    for curString in pastUrls 
    { 
     var myString:NSString! = curString as NSString 

     var substringRange :NSRange! = myString.rangeOfString(substring) 

     if (substringRange.location == 0) 
     { 
      autocompleteUrls.append(curString) 
     } 
    } 

    autocompleteTableView.reloadData() 
} 



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

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 

    let autoCompleteRowIdentifier = "AutoCompleteRowIdentifier" 
    let cell : UITableViewCell = tableView.dequeueReusableCellWithIdentifier(autoCompleteRowIdentifier, forIndexPath: indexPath) as UITableViewCell 
    let index = indexPath.row as Int 

    cell.textLabel!.text = autocompleteUrls[index] 
    return cell 
} 

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { 
    let selectedCell : UITableViewCell = tableView.cellForRowAtIndexPath(indexPath)! 
    textField.text = selectedCell.textLabel!.text 
} 

override func awakeFromNib() { 
    super.awakeFromNib() 
    textField.delegate = self 
    autocompleteTableView.delegate = self 
    autocompleteTableView.dataSource = self 
    autocompleteTableView.scrollEnabled = true 
    autocompleteTableView.hidden = true 
} 

override func setSelected(selected: Bool, animated: Bool) { 
    super.setSelected(selected, animated: animated) 

    // Configure the view for the selected state 
}} 

,你知道你不能定义厦门国际银行文件中标识

Image for the tableview cell

感谢

回答

2

您需要先注册一个带有autocompleteTableView的单元,然后才能将其解锁。修改你的代码是这样的:

override func awakeFromNib() { 
    super.awakeFromNib() 
    textField.delegate = self 
    autocompleteTableView.delegate = self 
    autocompleteTableView.dataSource = self 
    autocompleteTableView.scrollEnabled = true 
    autocompleteTableView.hidden = true 

    // Register cell 
    autocompleteTableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "AutoCompleteRowIdentifier") 
} 
+0

ty非常多! ,它的工作原理:$ –

+0

非常棒的男人!你能接受我的答案,然后:) – RaffAl

+0

当然,我做了;),你救了我! –