2015-09-14 5 views
0

У меня возникла странная проблема в моем проекте. Мой UITextField, UILabel и UIButton не отображаются во время выполнения, даже если все ссылающиеся выходы указаны правильноcustomCell UITextField в UITableViewController не отображается во время выполнения swift

здесь мой TableView код контроллера:

class ComposeMessageTableViewController: UITableViewController, UITableViewDelegate, UITableViewDataSource { 


@IBOutlet var composeMessage: UITableView! 

let composeCellArray = ["composeMessage"] 
override func viewDidLoad() { 
    super.viewDidLoad() 
    composeMessage.delegate = self 
    composeMessage.dataSource = self 
    composeMessage.separatorStyle = .None 
    composeMessage.backgroundColor = UIColor.whiteColor() 

} 

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

// MARK: - Table view data source 

override func numberOfSectionsInTableView(tableView: UITableView) -> Int { 
    // #warning Potentially incomplete method implementation. 
    // Return the number of sections. 
    return 0 
} 

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
    // Return the number of rows in the section. 
    return composeCellArray.count 
} 
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
    let composeCell = tableView.dequeueReusableCellWithIdentifier(composeCellArray[indexPath.row]) as! ComposeMessageCell 
    if(indexPath.row == 0){ 
//  composeCell.toLabel.text = composeCellArray[indexPath.row] as String 
//  composeCell.recepientTextField?.text = composeCellArray[indexPath.row] as String 
    composeCell.toLabel.text = "To" 
    composeCell.recepientTextField?.placeholder = "Recepients" 
    composeCell.addButton.tag=indexPath.row 
    composeCell.addButton.addTarget(self, action: "addMembers:", forControlEvents: UIControlEvents.TouchUpInside) 
    } 
    // Configure the cell... 
    composeCell.backgroundColor = UIColor.clearColor() 
    composeCell.selectionStyle = .None 

    return composeCell 


} 
@IBAction func addMembers(sender:UIButton){ 

} 

@IBAction func dismissnav(sender: AnyObject) { 
    dismissViewControllerAnimated(true, completion: nil) 
} 

} 

здесь tableviewcell код:

class ComposeMessageCell: UITableViewCell { 

@IBOutlet var toLabel: UILabel! 
@IBOutlet var recepientTextField: UITextField! 
@IBOutlet var addButton: UIButton! 

override func awakeFromNib() { 
    super.awakeFromNib() 

    toLabel.font = UIFont(name: "Avenir-Black", size: 16) 
    toLabel.textColor = UIColor.blackColor() 
} 

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

    // Configure the view for the selected state 
} 
} 

runtime Image

StoryBoard Image

Пожалуйста, дайте мне знать, где я буду неправильно

+0

ваш номер раздела установлен в 0 – Devster101

ответ

1

Ниже делегат должен возвращать 1

override func numberOfSectionsInTableView(tableView: UITableView) -> Int { 
    // #warning Potentially incomplete method implementation. 
    // Return the number of sections. 
    return 1 
} 
+0

спасибо .... но когда эта инициализация этого раздела действительно требуется, потому что в моих предыдущих случаях я достиг этого без инициализации раздела !! Любая идея? .. – ashwin

+0

numberOfSectionsInTableView инициализация по умолчанию возвращает 1. Если вы не даете реализацию, она будет принимать значение по умолчанию, тогда как когда вы даете реализацию, она должна возвращать 1. –

0

Как @Prabhu упоминалось делегат для метода:

override func numberOfSectionsInTableView(tableView: UITableView) -> Int { 

    return 1 
} 

всегда должен возвращать 1, которая по умолчанию или другое значение, установленное вами.

Смежные вопросы