2015-07-12 2 views
2

Я хочу создать три ячейки в контроллере tableview, и я добавил три ячейки прототипа в раскадровку, это не сбой, а просмотр пустой таблицы.Swift: три ячейки прототипа в TableviewController не будут отображаться

super.viewDidLoad() 

    // Uncomment the following line to preserve selection between presentations 
    // self.clearsSelectionOnViewWillAppear = false 

    // Uncomment the following line to display an Edit button in the navigation bar for this view controller. 
    // self.navigationItem.rightBarButtonItem = self.editButtonItem() 
    let nib1 = UINib(nibName: "one", bundle: nil) 
    tableView.registerNib(nib1, forCellReuseIdentifier: "one") 
    let nib2 = UINib(nibName: "two", bundle: nil) 
    tableView.registerNib(nib2, forCellReuseIdentifier: "two") 
    let nib3 = UINib(nibName: "three", bundle: nil) 

    tableView.registerNib(nib3, forCellReuseIdentifier: "three") 
} 

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 Incomplete implementation, return the number of sections 
    return 3 
} 

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
    // #warning Incomplete implementation, return the number of rows 
    return 1 
} 


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

// пусть клетки = tableView.dequeueReusableCellWithIdentifier ("reuseIdentifier", forIndexPath: indexPath) уага клетка: UITableViewCell!

switch (indexPath.row){ 
    case 0 : 
     cell = tableView.dequeueReusableCellWithIdentifier("one") as! one 
     cell.textLabel?.text = "book1" 
     break; 
    case 1: 
     cell = tableView.dequeueReusableCellWithIdentifier("two") as! two 
      cell.textLabel?.text = "book2" 
     break; 
    case 2 : 
     cell = tableView.dequeueReusableCellWithIdentifier("three") as! three 
      cell.textLabel?.text = "book3" 

    default: 
     break; 

    } 

    // Configure the cell... 

    return cell 
} 
+0

Когда вы обратитесь за помощью, обязательно задайте четкий вопрос. – ndmeiri

+0

извините, что непонятно – user3662992

+0

В чем вопрос? Вы только заявили о своей проблеме. – ndmeiri

ответ

1

Поскольку вы всегда будете хотеть ровно 3 клетки, чтобы показать в вашем представлении таблицы, вы должны использовать «Static Cells» стиль UITableView. Вы можете установить это в раскадровке, если вы выберете подходящий UITableView и посмотрите в Инспекторе атрибутов.

Затем вытащите правильное количество ячеек и настройте их в раскадровке. Подключите каждую ячейку к IBOutlet, если вам нужно программно манипулировать ими или их содержимым.

Обратите внимание, что поскольку статические представления таблиц разрешены только в UITableViewController, вам может потребоваться изменить класс, содержащий код, включенный в ваш вопрос.

+0

спасибо, если бы вы могли удалить ваш downvote :) – user3662992

+0

мой вопрос ниспровергнут от кого-то! – user3662992

+0

большое спасибо – user3662992

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