Table showing up in storyboard but not when running the app - iphone

I visually designed a table in storyboard, which displays six properties of an object. I can see the table in the visual editor, but for some reason, when I run the app, the table is not there.
Do I have to initialize anything, or ... ?
Here is screenshot

I know this is an old question. But I ran across the same problem and thought I would share the solution I found. When using the storyboard UITableViewController the implementation file autofills with methods and delegates for UITable. However, if you are using static cells you need to remove all of the implementation file table data source defaults (ie. numberOfSectionsInTableView, numberOfRowsInSection, cellForRowAtIndexPath)

Related

Creating a List of Custom Views in Xcode

I'm currently working on developing a desktop application for MacOS for downloading batches of audio files from URLs at one time I've run into a question about UI design that I can't figure out.
I have a class called SongEntry.swift that holds information regarding the URL that was entered (e.g. url, title, length, author, etc.) and I want to create a vertically growing list of custom views that updates when a new one is added.
Where is what the base view looks like:
Inside of the big white area is where I want the list to be held.
I've tried to create a separate view controller that handles each entry but that didn't work. I know UI design for MacOS is much different from iOS, however I think what I'm looking for is a way to simulate the table views and cell prototypes from iOS but can't find a suitable option.
If anyone knows of a possible solution or can point me in the right direction, I'd greatly appreciate it!
What you want is one of the collection views. For vertical list, you'll probably use NSTableView with only one column and hide everything else like headers.
Here are roughly the steps you need:
You can use your existing view controller or create a dedicate view controller for just the table (and use the 'embed' option in Interface Builder)
This view controller will adopt the NSTableViewDataSource and NSTableViewDelegate protocols to provide the data (your SongEntry objects) and the view for each row.
You set your NSTableView's source and delegate to your view controller.
You create a view which will serve as your "cell", it will be used by each row to display the data. You can design it either in IB or in code.
The entire process is described in detail in the Table View Programming Guide for Mac.
This topic can be a bit confusing. Note that there are two main approaches: the view-based and NSCell-based tables. Don't bother with the NSCell way, it's more of a legacy leftovers.
Also note that there are some overlap of methods in both NSTableViewDataSource and NSTableViewDelegate to provide data and views that can be a bit confusing at first. Just play around with the code and samples and it will be clearer which delegate method to use when.
There are many examples both on Apple's developer site and github. Also a good tutorial on raywenderlich.com.

Unknown class in Interface Builder file

Why am I still getting this error when I run my iPhone app? The file is a ViewController that I have been working to delete and replace, but it just won't die. As far as I know, I don't have any reference (string or otherwise) to this file in my project.
I have deleted the related file (I'm trying to get rid of it.)
I have cleaned the project and rebuilt.
I have "Reset Content and Settings" in my simulator.
I have done a grep (grep -i -r "TheClassName" *) and nothing matches except my UserInterfaceState.xcuserstate file.
I have searched the code using XCode's Find/Replace tab.
I have double checked my Build Phases and am pretty sure it isn't in there (its a large project).
Any other ideas? I've spent way too many hours trying to figure this simple thing out; I must be missing something.
Thanks!
Check your nibs or storyboard, and make sure none of your views are set to the class!
I finally fixed the problem after trying it on multiple machines over the course of almost 2 days! I will not be thwarted!
I tracked the problem down to a call to setViewControllers on a UINavigationController which is called on initialization of the application. I was always being passed 3 objects (there are 3 panes in the navigation controller). Even though I had deleted the third object, as previously explained, three objects would always be passed in. The class type of the first two was correct, but the third would just be a UIViewController. Curiously, this view controller had a nibName which corresponded to the object file and Xib file that I had previously deleted. Of course, when view was called on this borked UIViewController, it would crash since the corresponding nib had obviously been deleted. Remember, the textual name of this object or Xib could not be found in my directory with grep, so I have absolutely no idea how in the world it came into existence when I ran my app.
So, I figured the app may not have been cleaned properly. I double and triple checked this. I even validated that my Workspace settings were correct (File->Project Settings->Advanced). The app was indeed being recompiled fresh every time.
Secondly, I started thinking that perhaps the object was being set by some other means. Working backwards, I added some breakpoints and found out that initWithCoder was being called on the parent UINavigationController--this was eventually working down to call the setViewControllers on the object and assigning the three view controllers (one of which was the offending one). I could easily see from the call stack that the Nib file that was being loaded was deserializing something offensive.
So, I started digging into my Xib file. Of course, the object name wasn't in the file (as expected since the grep didn't find anything). I deleted and recreated the portion of the Xib that included my root UINavigationController. This ended up changing the Object ID and ref within the Xib file.
Secondly, I created a new Xib and UIViewController with the same names as the one which I had previously deleted, hoping that Xcode might be happy if I created and then re-deleted them. I then compiled, re-deleted them, updated by Xib file yet again, reverified with grep that yes, indeed, nothing existed with that name.
And it worked. After spending multiple days on this issues, I'm fairly sure that there is a bug here in the interface builder, but do I want to revisit this problem to file a bug report? Absolutely not...
In my case, I solved an issue by name of Custom class name of View instead of Custom class of ViewController. By mistake i added like this for view as shown below.
It Should be for ViewController like this.
This is in my case, for you may be it's related with another component.
This happens when the view class is in a framework. Select the framework's module. Example with a CocoaPod: HSegmentControl.
Make sure when you add or rename or move files around especially in folders, that when you add them you:
A. Create Groups, not references they don't usually read in.
B. Check the boxes for the apporpriate "Product(s) or Target(s)" you want to add the source to.
Another thing to try :
I had to toggle "Inherit from Target" under the "Module" control of "Custom Class."

Creating detail view content programmatically?

I am making an app which uses a splitviewcontroller and will have over 100 different pieces of content. I want to make it so when I select a row, the content changes dynamically. Before, I was creating 100 nib files and separate view controllers before realizing the inefficiency.
I want different labels shown in the detail view when I select a row.
As a guide, I am using the MultipleDetailViews sample code provided by apple.
Also, if anyone can help me out with how to have a button for back and forward (changing table view content) that would be great!
If they are the same just different labelled views, then you could create a single nib file with a view that has all the common elements and then perhaps, create a small template view in the nib which is not contained in the main view and is hidden by default, every time you switch to a new page you can the use you can then use you template view to build the fields for you page. You could also have a few different template views for the different kinds of fields you want to display. To store all this information to drive all of this, you can create simple property list files for each page which contain information like the field title, order, my type or width. Getting the path to a property list file from you app package is easy with methods like [[NSBundle mainBundle] patterForResourceOfName:extension:];, Using properties list can make it easy to change you app, it is even possible to add features like uploading of new nibs without having to resubmit you app to apple, just do a periodic search for new property list files from some server, parsing PropertyList files is really easer too, NSDictionary and NSArray all serialise them selves as property list.

Any code examples for using a UITableView to implement in-app settings?

Any code examples for using a UITableView to implement in-app settings?
That is where to get the iPhone settings app look and feel one custom builds the settings into a UITableView. So you you would custom set the sections and cells that get returned with switch type statements.
In particular interested in reviewing the coding approach for how to:
best configure the cellForRowAtIndexPath and didSelectRowAtIndexPath
how to handle those cells for which you want in cell editing (e.g. text)
those cells where you need to launch off into another screen to set a date/time for example
how to collect up parameters and pass back to calling rootViewController (in my case need to persist data out to Core Data persistence)
Note: using Core Data so not interested in using libraries such as InAppSettings [any feedback re whether such libraries might be ok appreciated at this SO question I created].
thanks
I am not sure if you can use the inappsettingskit for your needs. It is open source so you are free to modify the code as you wish, but it doesn't look as an out of the box solution.
If you want to make these settings available in the settings app you will have to live with some workarounds for example saving NSDate AND getting a nice UI control to modify it: Use a textfield, there is no control specified which let's you pick a date. Have a look at Apple's documentation.
So the last option will be coding. First of all, determine what kind of types you want to support. Then create custom TableViewCells which reflect those kinds. If some kinds do need some special way of editing, for example a color picker, you'll have to write those controllers as well. You set a cell into editing mode with the delegate method tableView:didSelectRowAtIndexPath and present the custom controller or get into editing directly for example a UITextField. A Slider is handled directly without any coding.
The cells will need some kind of identifier so you can identify those in your model. A TableView and Core Data can interact with each other pretty well by using the NSFetchedResultsController. Create a simple window based app with a template and check the Use Core Data for Storage. The rootViewController illustrates how a tableView works together with Core Data. For your case it will be getting a bit more complicated as inserting a row will have to determine what kind of cell it should add.
I think you should look into this and get back with some more specific questions.

Question regarding iPhone core data and how to duplicate features for multiple users...that doesn't make sense, just read my question :)

So I am working on a simple iPhone app, that uses core data to manage objects. My code is similar in function to Apple's CoreDataBooks app, found here. There is a blank UITableViewCell, and you have the ability to add objects to this blank list. If you hit the add button, a DetailViewController pops up that manages the attribute of each object. In the coredatabooks example, the app is like a library, and you can add book objects. My question is about how I might go about making it so that multiple users can have their own separate list of these objects. Again, relating back to coredatabooks, you would be able to make different library objects whose attributes are the book objects themselves. So using the convenient and easy to use coredata ui, would it be very hard to set it up so that in the UITableView, there was Library-A and Library-B and then selecting one of the libraries would move me to a screen that has the list of different books unique to that specific library? If you then select a book, you would then be able to view that book's attributes as before. So I guess my question is regarding how to put another RootViewController-esque view in front of the native one. As you may gather from this post I am in the learning stage of iPhone development, so I don't even know if logically this is even feasible or the correct way to do it. Any help/insight on this matter would be greatly appreciated! Thanks for your patience!
Create another UITableViewController (.h, .m, .xib files). And you can put some functionality into that view controller for adding library.
You can set that viewcontroller as startup object from MainWindow=.xib file. OPen that xib file -> expand navigation controller -> click on root view controller.
then in attributes window you can select your new controller as startup. you have to also set startup class from identity window.
Ruchir is correct, you can add another table view and controller. You will have to make some adjustments so that it is loaded and displayed first.
Also, it sounds like you will want to create a new entity in your data model for a Library which should have a to-many relationship with the Book entity.
Library <-->> Book
The new table view controller can use a fetched results controller that fetches Library entities. When the user chooses a row, you can set a property on the books table view controller before you push it on the navigation stack. Then use a predicate on the books fetched results controller to only fetch books in that library.