import UIKit
class ViewControllerM: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var ZayTableView: UITableView!
var data = [
["dfghdfg","sfgsfgsg"], ["sdgsd", "sdfgvsd"]
]
var p: Int!
@IBOutlet weak var menuBarButtonItem: UIBarButtonItem!
// Переход на меню
var menuVC: MenuViewController!
override func viewDidLoad() {
super.viewDidLoad()
menuVC = self.storyboard?.instantiateViewController(withIdentifier: "MenuVC") as! MenuViewController
let swipeRight = UISwipeGestureRecognizer(target: self, action: #selector(handleSwipe(_:)))
swipeRight.direction = .right
let swipeLeft = UISwipeGestureRecognizer(target: self, action: #selector(handleSwipe(_:)))
swipeLeft.direction = .left
self.view.addGestureRecognizer(swipeRight)
self.view.addGestureRecognizer(swipeLeft)
let nib = UINib(nibName: "CustomCell", bundle: nil)
ZayTableView.register(nib, forCellReuseIdentifier: "customCell")
ZayTableView.backgroundColor = UIColor.darkGray
p = 2
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return data[p].count
//return data.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "customCell") as! CustomCell
let str = data[p][indexPath.row].components(separatedBy: " ")
cell.customInit(text: str[1], accessoryText: str[0])
return cell
}
@objc func handleSwipe(_ gesture: UISwipeGestureRecognizer) {
switch gesture.direction {
case UISwipeGestureRecognizerDirection.right:
// print("Right")
showMenu()
case UISwipeGestureRecognizerDirection.left:
// print("Left")
hideMenu()
default: break
}
}
@IBAction func menuBarButtonItem(_ sender: UIBarButtonItem) {
if AppDelegate.isMenuVC {
showMenu()
} else {
hideMenu()
}
}
// Функция открытия меню
func showMenu() {
UIView.animate(withDuration: 0.3) {
self.menuVC.view.frame = CGRect(x: 0, y: 60, width: UIScreen.main.bounds.size.width,height: UIScreen.main.bounds.size.height)
self.addChildViewController(self.menuVC)
self.view.addSubview(self.menuVC.view)
AppDelegate.isMenuVC = false
}
}
// Функция закрытия меню
func hideMenu() {
UIView.animate(withDuration: 0.3, animations: {
self.menuVC.view.frame = CGRect(x: -UIScreen.main.bounds.size.width, y: 60, width:UIScreen.main.bounds.size.width, height: UIScreen.main.bounds.size.height)
}) { (finished) in
self.menuVC.view.removeFromSuperview()
AppDelegate.isMenuVC = true
}
}
// Пэйдж меню заявки и мониторы
@IBAction func switchCustomTableViewAction(_ sender: UISegmentedControl) {
p = sender.selectedSegmentIndex
ZayTableView.reloadData()
}
}
из этого vc есть два перехода , на меню, и на две вкладки, пока был только переход на меню, все работало, добавил код с вкладками, появилась фатальная ошибка, с tableview. вот второй vc где прописано меню
import UIKit
import WebKit
class MenuViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var menuTableView: UITableView!
let Mytitle = [" Обновить", " Проверить соединение", " О программе", " Поддержка", " Выйти из учетной записи"]
// кнопка обновить
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if indexPath.row == 0 {
let UnameViewController: unameViewController = self.storyboard?.instantiateViewController(withIdentifier: "unameViewController") as!
unameViewController
self.navigationController?.pushViewController(UnameViewController, animated: true)
}
// Кнопка Проверить соединение
if indexPath.row == 1 {
if functionViewController.isConnectedToNetwork(){
//print("Internet Connection Available!")
let alert = UIAlertController(title: "Соединение с интернетом", message: "Отлично", preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))
self.present(alert, animated: true, completion: nil)
} else {
let alert = UIAlertController(title: "Соединение с интернетом", message: "Нет соединения", preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))
self.present(alert, animated: true, completion: nil) }
}
//кнопка выйти
if indexPath.row == 4 {
// UIControl().sendAction(#selector(NSXPCConnection.suspend),
// to: UIApplication.shared, for: nil)
let vs = self.storyboard?.instantiateViewController(withIdentifier: "ViewController")
self.present(vs!, animated: true)
/* let ViewControllerP: ViewController = self.storyboard?.instantiateViewController(withIdentifier: "ViewController") as!
ViewController
self.navigationController?.pushViewController(ViewControllerP, animated: true)*/
}
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
menuTableView.delegate = self
menuTableView.dataSource = self
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return Mytitle.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = menuTableView.dequeueReusableCell(withIdentifier: "MenuCell") as! MenuTableViewCell
cell.labelText.text = Mytitle[indexPath.row]
return cell
}
}