0

I'm new in Swift, and now I'm trying to develop an app. I need to show UITabBarController with 3 tabs. Each tab has the same ViewController (it is custom class, inherited from UIViewController).

Sequence of my actions:
1. Put TabBarController in storyboard, dropped Tab1 and Tab2 which were situateed in it by default, and pointed a custom class (ArchiveTabBarController) and Storyboard ID (ArchiveTabBarVC).
2. Put UITableViewController in storyboard, pointed custom class (ArchiveTableViewController), and pointed storyboard ID (archiveTableVC).
3. Made a custom cell in this TableViewController: pointed a custom class (ArchiveTableViewCell), and pointed identifier (archiveTableViewCell).
4. In my ArchiveTabBarController, I wrote such code:

override func viewWillAppear(_ animated : Bool) {
    super.viewWillAppear(animated);
    let item1 = ArchiveTableViewController();
    item1.archiveType = "";
    let item2 = ArchiveTableViewController();
    item2.archiveType = "type1";
    let item3 = ArchiveTableViewController();
    item3.archiveType = "type2";   
    let controllers = [item1, item2, item3];
    self.viewControllers = controllers;
}  
override func viewDidLoad() {
    super.viewDidLoad();
    delegate = self;
} 

In my ArchiveTableViewController, in viewDidLoad(), I make GET-Request to load data. Result depends on archiveType.
5. In my mainMenuViewController, I made transition to the ArchiveTabBarController.
And the problem is: when I'm trying to go to the ArchiveTabBar, it fails with error: unable to deque reuasble cell with identifier "archiveTableViewCell". But when I dropped TabBar, and tried to go to the ArchiveTableViewController, it worked fine.

What is my mistake?

user3533397
  • 191
  • 1
  • 2
  • 14
  • Provide your project link , so that i can fix the problem ! – dip Jul 19 '17 at 07:06
  • Sorry, but I don't know, what is project link - it is situated in my device only. – user3533397 Jul 19 '17 at 07:08
  • I tried to register reuse identifier directly in code. Now it fails with error "Unexpectedly found nil while unwrapping an optional value", when I'm trying to set text in label in my custom cell. – user3533397 Jul 19 '17 at 07:28
  • Additional information^ I tried to add seque in Storyboard, between my ArchiveTabBarController and ArchiveTableViewController. It works. But if I'm trying to add controllers programmatically, it fails. What's wrong? Maybe, I should register something in my ArchiveTableViewController? – user3533397 Jul 19 '17 at 08:55

2 Answers2

0

So, I tried next:
in my ArchiveTableViewController, in viewDidLoad(), i put next:

tableView.register(UITableViewCell.classForCoder(), forCellReuseIdentifier: "archiveTableViewCell")

And in cellForRowAt, I used standard text field for stanard cell. Everything works fine. So, the problem is in the cell's registration. Anybody can help with it?

user3533397
  • 191
  • 1
  • 2
  • 14
0

Finally, I did this! I read questions custom UITableCellView programmatically using swift and Custom UITableViewCell register class in Swift, and more questions, and decided to try register XIB file. I created TableViewCell from scratch with XIB, and everything works.

user3533397
  • 191
  • 1
  • 2
  • 14