1

So I'm working in XCode 5 and iOS 7 and am trying to add editable UITextFields to a series of UITableViewCells. It all looks good on the storyboard, but when I run the app, there's no text visible in the cell and the cell doesn't allow editing.

Screenshot of how it looks in the storyboard: screenshot

In the app, it's just a couple of blank cells. Any thoughts?

Community
  • 1
  • 1
nickd717
  • 181
  • 2
  • 12

2 Answers2

2

please refer to UITableView with static cells does not appear

One more thing about static cells, they only work in UITableViewController. The Storyboard Editor will let you add them to a Table View object inside a regular UIViewController, but this won’t work during runtime. The reason for this is that UITableViewController provides some extra magic to take care of the data source for the static cells. Xcode even prevents you from compiling such a project with the error message: “Illegal Configuration: Static table views are only valid when embedded in UITableViewController instances”.

Community
  • 1
  • 1
lanbo
  • 1,678
  • 12
  • 12
  • Static cells. Looks like I can do this in code by setting the data source, but is there some way to add the text fields in storyboard to avoid a long series of if/elseif/elseif... for a variety of different input types? – nickd717 Sep 29 '13 at 07:06
  • Also, seems to work similarly whether it's static cells or dynamic prototypes. What's functionally the difference? – nickd717 Sep 29 '13 at 07:06
  • I did a quick test on static cells, no need to implement the - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath and the cells will be displayed automatically on tableview. dynamic tables: the cells' data need to be updated during runtime, – lanbo Sep 29 '13 at 07:13
  • The text fields show up and are editable with static cells and no overriding of cellForRowAtIndexPath? Do you have any insight on what I'm missing? – nickd717 Sep 29 '13 at 07:16
  • I guess you have - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 0; } so no cells will be displayed on screen – lanbo Sep 29 '13 at 07:19
  • I don't have the protocol implemented - took that out because I was trying to just do it in storyboard. – nickd717 Sep 29 '13 at 07:25
  • can you make a demo project and upload to somewhere and see if I can help? I did a quick demo with only storyboard, no view controllers, with two static cells like you did(no border style), the text fields can be edited – lanbo Sep 29 '13 at 07:28
  • github.com/nurepnick/test is just a empty project, I do not see any cells in any of the story board – lanbo Sep 29 '13 at 07:54
  • Uploaded again - nothing in the iPad storyboard? – nickd717 Sep 29 '13 at 07:59
  • 1
    sorry, I checked it does not work, the static cells are not supported on a generic view controller, it will only work with a UITableViewController – lanbo Sep 29 '13 at 08:11
  • Ah well, guess there's not really a way. – nickd717 Sep 29 '13 at 16:29
1

Though I figured it out lately that if your static tableViewCell shows in storyboard but doesn't appear in runtime only because of your UITableViewController class has numberOfSections() & tableView() function. If you really want to show static table view cell then just remove those functions and it'll appear in runtime. you need to just have only viewDidLoad() func in your class like this

class MenuTableViewController: UITableViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
    }

}
Al Walid Ashik
  • 1,545
  • 20
  • 32