September6
If you need to display differing size text in a UITableView here is some sample code that uses standard UITableViewCells and changes the height depending on the size of the Table View (handles rotation ok).
The main sections of code is the heightForRowAtIndexPath:
NSString *bigText = [self.bigTexts objectAtIndex:indexPath.row];
CGSize textSize = [bigText sizeWithFont:self.labelFont
constrainedToSize:CGSizeMake(tableView.frame.size.width - 40.0, MAXFLOAT) //40 should be the margin needed for controls etc.
lineBreakMode:UILineBreakModeWordWrap];
return textSize.height;
And the initialisation of the TableViewCell:
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell.
cell.textLabel.numberOfLines = 0;
cell.textLabel.lineBreakMode = UILineBreakModeWordWrap;
cell.textLabel.text = (NSString *)[self.bigTexts objectAtIndex:indexPath.row];
cell.textLabel.font = self.labelFont;
return cell;
I have uploaded the complete project for those who want to run it straight out of the box.
December28
Came across an interesting problem. Trying to get distributed objects to pass a common class between processes.
To avoid versioning issues I had the class in a shared location so that both client and server could use it.
On the server I was seeing a decodeRetainedObject: class ‘bleh’ not loaded error in the console log. Took a while to figure out, but XCode doesn’t automatically assign a class that are dragged and dropped into a project to the main target. The files simply needed to be assigned to the requisite target and everything works fine.
April13
I have been hunting for information about NSSplitView and ran into a couple of sites with some decent information about Split Views and its intricacies.
Split View Help:
http://homepage.mac.com/jrc/contrib/ — Code for collapsing NSSplitViews programmatically.
http://www.cocoadev.com/index.pl?RBSplitView — An implementation of splitviews which gives you more control.
Generally Useful Site:
http://borkware.com/ — I am surprised I haven’t come across this site before. Seems to have a heap of useful code snippets.
I will let you know how I go with the intricacies of the NSSplitView
April7
The new version of Body Diary presents a list of additional fields to the user to fill in. The number of fields is determined by the user. This data hasn’t been assigned to coredata so I decided that the easiest way to show this would be to create a mutable array and have that as the data source for Cocoa Bindings. Whenever a record is added to the system the array is recreated.
My first attempt at working with the data I went straight to the array and editted the data. This left the display out of sync with the data. A quick scan of the documentation pointed out that I should be instead using the NSArrayController to manipulate the data. I modified my code but I was soon stuck with nothing working. I tried everything, recreating controller objects, modifying my code, stepping through line by line. Nothing worked and I was getting very close to just rewriting everything as traditional table delegate methods.
I decided to remove all my debugging trials and strip everything back to the bare essentials. Once I did this I noticed that the class controlling the window was crashing when I quit. It turns out that my code to set the MutableArray that the NSArrayController was using was back to front. So instead of retaining the newArray, releasing the old, and then assigning the new to the old, I was retaining and releasing correctly but was assigning the old to the new.
A quick switch of the code and my NSArrayController was behaving perfectly. So the old “Problem Exists Between Keyboard and Chair” strikes again.
April6
I was having a discussion with R. Tyler about getting 2 entities to combine into 1 table using CoreData/Cocoa Binding. We stretched the NSArrayController in all sorts of ways trying to get it to do something that it didn’t want to do.
Anyway I had a think about it over dinner, and it occurred to me that the solution probably isn’t in Interface Builder but in the model itself. After a bit of fiddling and some trial and error I found that it wasn’t too hard to accomplish. The basic twist that is needed is that you should have an abstract entity which is a parent for the two entities that you wish to combine.
The hook an array controller up to the parent entity and it will display all of the appropriate records. The only gotcha I found was that if your two entities have different fields that you want to display the missing fields will have to be added to the entity. Set these to transient so that the data saved in them will be ignored during saves.
I have a simple sample project up to demonstrate what is happening.
April4
I have started working with core data for a couple of days now and I have a few first impressions:
The initial core data videos and tutorials take the easy path and show you the add a row to the table/delete a row from the table type example. The first version of Body Diary worked this way and I had a number of complaints about the user interface. It takes a little more effort to get this working correctly.
The bindings dialogs aren’t really intuitive. As I get used to the interface I am sure that I will understand it better once I have used it for a while.
I like the core data entity and relationship mapping. To me it feels like building a ER diagram for a database without having to worry about primary keys and foriegn key mappings. I would like to be able to drag and drop the relationships but that is probably a symptom of me spending to much time using Visio to document peoples databases.
In all I can see how core data will help me be more productive. Hopefully I will be able to climb up the initial learning curve in the next couple of days (I only get a couple of hours a day to work on Body Diary) and then bask in the speed that is developing applications using core data.
April2
I have decided to rewrite Body Diary using Core Data, after seeing Apple’s video tutorials on Core Data. Previously Body Diary hasn’t used either Core Data or Bindings, so this version will be a complete rewrite. The reason for using core data are:
- Faster coding
- No coding of sorting/filtering routines
- Should create an app with better stability
- I probably should learn these brand new technologies
Body diary is a pretty simple application so it should be an easy introduction for me to Core Data. The only real challenges I see with Body Diary are:
- Need custom code to handle the charting module
- Need code to import existing Body Diary files.
Also body diary will have a couple of new options. The main request people have is that they want to include an extra field or two. The main problem is that different people want to include different fields. Therefore I hope to incorporate the option to add any number of additional fields to the body diary application, and to chart those fields. The other main request is
for the charting module to show a floating average on the chart. I will also include the option to filter the results so you can view the graph for a set time frame.
Before diving in I thought I would read up a bit on Core Data. I have found the following useful: