I started working on my first real app, called Chauffage. This app should help us with our billing. It helps calculating the heating cost of our gites. This app should be fairly straightforward and involves Core Data and TableViews. I need to input various types of data (string, integers, floats, dates and a pick list). So it gives me a chance to dive a bit deeper into things. It should however be ready in a few days.
However I did come across a few issues and errors of mine that took more than average time to solve:
- White startup screen - the first time I stared the app, nothing happened. I just got a white screen. I discovered that even my first scene was not called. The I had the good idea to look in the app delegate. And by comparing with earlier apps, I discovered that there was some code that should not be there. Indeed deleting that code, did start my application. I guess that I started out with the wrong template;
- Database not opened - I had trouble accessing the database. After looking into the flow more deeply, I discover that the database was not opened yet, when I tried to access it. I just was to quick. So now I put the access part in the completion handler part;
- Singleton not initialised - at some stage I noticed that my context was not saved. I was smart enough to print an error in case. The error was however NULL. After looking around on Internet, I found that the issue was the context was nil, so it was not initialised. After following the flow around the singleton, I saw that I forgot to add this global database variable to the singleton;
- Inline editing - I wanted to add the possibility of inline editing of a tableview cell. After a lot of digging I decided to create a subclass of a UITableViewCell. I configured that cell with an UILabel and a UITextField properties. Then I created the corresponding view. In the tableview:cellForRowAtIndexPath:, I created a cell based this subclass and view (need to load the corresponding nib-file). The cell-properties allow me to fill in the label and the placeholder for the textField. And most importantly I set a textField.tag based on the row of the tableView. The class with the tableView is also the delegate for the textField. In the delegate method didFinishEditing I check the tag to find out the row of the tableView, so I can update the right properties;
- NSMananagedDocumentContext changed - a tried to insert a new Managed Object in the database, but was struck with an error without warning code. In the debugger I found an method where the bug roughly occurred. Searching on the Internet, I found that the problem was that the context changed. Next step was to find out where that happened in my code. It turned out that I re-read my document-files and was thus assigned with a new context. Getting rid of that solved the issue;
- Defaults Bundle not used - I created a bundle to hold the default values, which can be changed through Apple’s Preferences app. Took me a while to find the correct and understandable directions. I though I could subsequently access this bundle through the standardUserDefaults method. However that was not the case. One has to setup things before in the application delegate method AppDidFinishLoading (or something like that). Apple has a nice example, which I could use;
- Localisation literals - I did a localisation of all the texts occurring in the app. I thought I would be smart and use #define to create all the texts. Especially as the same text occurs now and then. However the ‘gentexts’ macro does not like literals. So I had to change all again.
- Button title localisation - I thought being smart by creating all the button titles in the application and not the interface. I adapted the size of the button to accommodate the length of the titles. However this does not work well. The size of the text-button label does not seem to be adapted, so text is still cut. Furthermore after pressing a button there is a relic of the title I put in the scene. Turns out that I have to set the title from code for all possible four states;
- Read/Write mismatch - I seem to have a problem reading and writing. I write some changes to disk and after that retrieve the data again. It seems however that the ‘after’ happens after the retrieving, so I do not see the changes. However when I restart the app the changes are there. I added the CoreData controller used in the cs193p course, which helped a bit. The FetchedResultsController has to detect changes. However it does not seem to see all changes. Need to do some more testing.
I am about to wrap this phase up. The app is working. Now I can deploy privately and do some testing in practice.