reloadData() and setting IBOutlets without Interface Builder - ios

I have created a UITableView inside my UIViewController programmatically using this guide on the Speak Objectively Blog.
However I now have the problem that .reloadData() isn't refreshing the view. However if I drag or move inside the UITableView the data appears correctly.
This answer suggests that I haven't set up the outlet. To my understanding IBOutlets are for connecting elements in the Interface Builder to the code. Please correct me if my understanding here is wrong.
How do I set an outlet if I created the UITableView programmatically?

The guide creates a UITableViewController. It has already an instance of UITableView on it, and it is the one you see in screen. There's no need of creating outlets, so that answer is not actually the answer to your problem (but might be somehow related)
What I can imagine is that you are sending the message somewhere else.
As you can see in the Table View Controller Class Reference , you can get your table view by self.tableView (or just tableView in swift)
So make sure you are sending the message to self.tableView.reloadData()
If it doesn't work, sending part of your code will help us to see better than to imagine where could be the problem ;)

If self.tableView.reloadData() doesn't work on its own, use:
dispatch_async(dispatch_get_main_queue(), {self.tableView.reloadData()})
or
dispatch_async(dispatch_get_main_queue()) {self.tableView.reloadData()}

Related

Error in UITableView Section Header

I have an ios app written in swift. I am trying to make an input form using Eureka. So first I copied its example code into my FormViewController. The code is exactly same of RowsExampleViewController in the example code. The resultant output is following:
The expected output (as shown on github page of Eureka) was:
As you can see that the Section Headers are floating for some reason and not properly formatted.
Whats is the possible problem I should look at? Please let me know which section of code should I paste. The ViewController code is exactly same as that of example.
Also, I faced similar problem while using SwiftForms. I think there might be some connection.
I just had this happen when I used a UITableViewController in the storyboard and set its class to be my subclass of FormViewController. I ended up removing it and using a UIViewController instead, placing a table view as a subview of the VC's view.
I think the problem is, if you use a UITableViewController it has some of its own assumptions and settings, and the FormViewController is creating its own, so you end up with two section headers at the same time.

Moving UITableView in xib

I have a simple question for you.
I load images and strings from sqlite3 base. If there is no image, i want to move up my table view.
How can I realize it? I tried to change frame.origin.x, but it doesn't work.
Link to my project https://github.com/serg1991/diplom
Can you be more specific about the exact position of your problem in your project? It's kinda big.
Also, if you need to move up your view, what you want to modify is frame.origin.y.
Otherwise, make sure you don't change your tableView's frame too early in the view lifecycle. Try doing that in the -viewDidLoad of your controller.
Be sure not to use a TableViewController in storyboard... Use a viewController, and drag a tableview inside (of course now you'll have to manage the delegates your self).
Hop this can help

Custom UITableViewCell class in Xcode 4.2

I've been following this Apple Doc to add a custom UITableViewCell that I layed out in an .xib to my project. One problem with the doc is that it seems like it was written for an older version of Xcode.
I'm able to load my UITableViewController that the custom cells are on, but the cells are all blank. My custom cell contains several UILabels, and has a non-default background color. The table that appears when I run has the default white background and no labels. If I change the UITableView's View -> Background on my storyboard, the color of the cells' background changes, but the labels still don't appear.
Of interest is the fact that the data is still in my table's cells. The UITableViewController is itself called as a popover from another controller. When I select one of the cells, the strings from the various label.texts are supposed to be loaded into their own labels on the popover's delegate, and that code works fine (except when I try to include a UINavigationBar in my popover, but that's probably another issue entirely).
I'm still pretty new to iOS developement, so if there's anything I'm leaving out or being unclear about let me know.
Edit - cleaned up code, now is completely different question than when I originally posted, but is still on the same topic. Should I have deleted the old question and posted this as a new question all together, or is it alright that I just edited it?
I'm still not entirely sure what was wrong with what I was doing before, but I managed to get what I wanted. I originally dropped a UITableViewController onto my storyboard set up a popover segue (also on the storyboard) and tried to display the popover with performSegueWithIdentifier. Instead, I now create the popover completely in my code (which I found a nice tutorial for here on SO, by goggling "show popover programmaticly"), without having anything for it on my storyboard. That seems to be the most documented and stable way to show a popover. Once I displayed it that way, my custom cells showed up exactly like I wanted.

ipad populating table with coredata

Please help with this issue that is driving me insane...
I want to populate a table with coredata (in a UIViewcontroleer), not a UITableController, as I need the table to be small and not take the whole screen,
I have tried different approaches, to no avail, and no answer to fix the problems,
Im adapting some code from tutorials that use the whole screen,
example problem, Request for member tableView in something not a structure or union
all my searches for code show the use in iphone with tableview, It would be awesome if you know of a sample for ipad with a view controller (not in split view),
thanks in advance
Your error stems most likely from you using the tableView property which is not available in UIViewController. It's difficult to judge what you did wrong, did you implement the necessary UITableViewDataSource and UITableViewDelegate methods? If you implement these it's no problem to use a UIViewController with core data. But remember the UITableViewController does more than just fill the table, it also resizes the table view when the keyboard is shown. You'll have to do this yourself, too.
UITableView has a rowHeight property that you can set directly or via the delegate method tableView:heightForRowAtIndexPath:.
UITableViewCell has a font property that you can set, to make the font smaller.
UITableView class ref says rowHeight is in points. If that means the same as points in NSFont, it should be easy to coordinate the two.
And of course you can resize the table view’s frame in IB.
So you ought to be able to get what you want using a UITableViewController.
As for the error, do you know what line is generating it? Have you set breakpoints to find out?

MonoTouch: UITableView outlet variable is null

I am running through the "Navigating with tables" section of Wrox' Professional iPhone Programming with MonoTouch by McClure et al, picking up the basics of putting together a hierarchical UI for iOS, and running into the following problem.
I have created a new "iPhone View with Controller" file (called ParametersViewController), deleted the UIView from it, added a UITableView, created an outlet for it (tableView) and connected the "File's Owner" view outlet to the UITableView, per the tutorial.
In the RowSelected method of this view's parent view, I instantiate my ParametersViewController, calling the default constructor, in which I want to set up the table view's data source:
this.tableView.Source = new DataSource(this, new [] {"one", "two", "three"});
(DataSource is a nested class which inherits from UITableViewSource)
All compiles and runs fine, up until the point where that line is executed. Turns out that this.tableView is null, so I get a NullReferenceException.
tableView is the outlet for the table. How can it be null? Can't I set up the table source here in the constructor? If not, where do I do it?
Solution to this was
Don't create an outlet called tableView
Make the view a subclass of UITableViewController, instead of UIViewController
Refer to the base.TableView property of my UITableViewController, rather than the nonsense outlet I created
I'm not 100% clear on what you're doing where, but it might be that you need to access your UITableView in the UIViewController's ViewDidLoad method. At that point your NIB view(s) should be instantiated.
If that's not the problem, it may help if you could provide some more code so that we can see exactly what's going on. I think the lack of responses might due to people not being sure that they understand the nature of your problem exactly.

Resources