Я новичок в разработке мобильных приложений iOS и Swift. Я пытаюсь внедрить UITableViewController, который может выполнять следующие действия:Как переключить ячейки ячейки в UITableViewController в SWIFT?
- При нажатии на любой из заголовков разделов ячейки, соответствующие этому разделу, должны опускаться.
- После нажатия на заголовки разделов, в которых есть 0 ячеек, должен быть запущен сеанс segue и нажат на другой ViewController.
0 cells -> push to different ViewController.
n cells -> выпадающий список
Как достичь этого в Swift?
Я пробовал использовать следующий код в UITableViewController для переключения, но, напрасно.
override func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let frame: CGRect = tableView.frame
let button = UIButton(type: UIButtonType.System) as UIButton
button.frame = CGRectMake(5, 5, frame.size.width-10, 80)
button.addTarget(self, action: "menuButtonAction", forControlEvents: .TouchUpInside)
if section == 1 {
button.setTitle("Home", forState: UIControlState.Normal)
}else if section == 2 {
button.setTitle("Profile", forState: UIControlState.Normal)
}else if section == 3 {
button.setTitle("Projects", forState: UIControlState.Normal)
}else {
button.setTitle("Title", forState: UIControlState.Normal)
}
let headerView = UIView(frame: CGRectMake(0, 0, frame.size.width, 150))
headerView.addSubview(button)
return headerView;
}
var enabledCategory:Bool = false
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
if (section == 3 && enabledCategory){
return dataHandler.getNumberOfProjects()
}
else {
return 0
}
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("menuCellIdentifier", forIndexPath: indexPath) as? TableViewCell
// Configure the cell...
if indexPath.section == 3 {
cell!.customLabel.text = String(indexPath.row)
}
return cell!
}
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
if indexPath.section == 3 {
enabledCategory = !enabledCategory
tableView.reloadSections(NSIndexSet(index: 3) , withRowAnimation: .Fade)
}
}
И, я не имею ни малейшего представления о том, как нажать на другую ViewController, нажав на разделы 1 и 2.
Спасибо.
Нет. Вы должны предоставить то, что попробовали, тогда мы сможем помочь вам в этом. Никто не напишет ваш код для вас. – rMickeyD