Checklists, p. 266, Chapter 12: Can't see or tap on the Text Field

Everything looks the same in my storyboard, but when I click on the + button in order to add an item, I don’t see the Text Field that I added to the AddItem Table View:

Maybe I don’t understand the instructions to, “Tap on the cell”. How do I tap on a cell in the simulator? I tried clicking all over the Table View, but nothing happens.

The “Note” with hints on what to do if the keyboard doesn’t appear don’t work for me either.

I tried deleting the Text Field, then rerunning the app, and the Add Item Table View looks the same, so it seems to me that for some reason the cell will not display the Text Field.

Xcode 9.2/iOS 11.2

Here are some screen shots of my storyboard before I added the Text Field and after I added the Text Field:

In the Simulator, under Hardware>Keyboard I see the choices:

Send Menu shortcuts to device
----
Use the same keyboard language as macOS
Connect Hardware Keyboard
Toggle Software Keyboard

and the following are checked:

Use the same keyboard language as macOS
Connect Hardware Keyboard

I tried giving the Text Field a border and a green background color, but I still can’t see the Text Field after clicking on the + button to add an item. I also tried adding a Label to the cell, and I can’t see the Label either. So nothing I add to a static cell is displayed by the Table View.

1 Like

I don’t recall where the instructions to “tap on the cell” appears but since you don’t have a cell displaying when you run the app, that won’t work. It looks as if your Add Item table does not display any rows based on the screenshot. The question is, why.

The screenshots you’ve provided aren’t sufficient enough for me to easily figure out what is going on. Can you please upload your project somewhere and provide a link here? I can then take a look and tell you what might be wrong.

I don’t recall where the instructions to “tap on the cell” appears

The location is in the title of my post. :slight_smile:

I tried deleting the Add Item Table View Controller in the storyboard and redoing the steps, but I got the same result. Thanks for taking a look:

https://github.com/7stud/Checklists1

The instructions on page 260 for creating AddItemViewController says to remove all the boilerplate code except for the viewDidLoad implementation. However, your code in AddItemViewController contains the following:

override func numberOfSections(in tableView: UITableView) -> Int {
    // #warning Incomplete implementation, return the number of sections
    return 0
}

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

The above is boilerplate delegate code for the table view which sets the row count to 0. This code still affects the table view even if it contains static rows. That’s why you are not seeing your static row since the code above tells the table view that there are no rows to display :slight_smile: Remove that code and everything will work fine.

2 Likes

Arggh! Thanks for betting back to me so quickly! I wrongly assumed that instruction was just to tidy up the file. :blush:

I find it strange that the defaults would be 0 sections and 0 rows, rather than something like 1 section and 3 rows.

A default of 0 and 0 causes the least issues since the default is also tagged with a compiler warning indicating that you do need to change it. If you have a default indicating a non-zero value, but do not have any data, the app will crash …

1 Like

I don’t see a compiler warning related to the boiler plate code when I create a test project in which I add a TableViewController. The only compiler warning I see is the typical “reuse identifier” warning.

If you have a default indicating a non-zero value, but do not have any data, the app will crash …

Okay, that seems like a good reason not to use non-zero values as the defaults…however my test app does not crash when I run it with the boiler plate code containing zero values for the number of sections and number of rows. Instead, I see a tableview with a screen full of rows. Apparently, the “sections” function gets called three times and the “rows” function is never called when the app launches.

I believe the boilerplate code included a warning but I might be mistaken. You can check out the boilerplate to see what is there … Also, whether the warning appears or not might be controlled by some Xcode setting. You should be able to figure out that bit with some Googling :slight_smile:

Not quite sure what you mean here since with zeros for row and sections, you should not get a crash. But if you did add non-zero values there, it still probably might work correctly for static table views. But for non-static ones, where the delegate has to actually provide the cells, you would see a crash. That is what I meant.

Ah, I misread your answer. You actually said with defaults of something like 1 and 3, as I suggested, the app would crash–not the boilerplate defaults of 0 and 0.

I believe the boilerplate code included a warning but I might be mistaken.

The boiler plate code included a comment that said:

// #warning

I guess there is some setting that will cause that comment to generate a compiler warning.

Thanks for answering all my questions! Onward! Although, I spent the downtime going through the raywenderlich Xcode git tutorial., which was a nice side track.

This was super helpful- I also erroneously followed the text & video tutorials without double-checking the tableview boilerplate! Thank you both :hugs:

This topic was automatically closed after 166 days. New replies are no longer allowed.