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.
July19
Unless you are building a custom UI (like a game) on the iPhone you probably spend a lot of time working with UITableVews.
I often found it difficult to find good simple examples of iPhone TableView code.
This first sample shows three different uses of UITableView:
1) Very basic table
2) Table that can be resorted.
3) Table that can be resorted with the first and last rows locked in place.
Click on the plain/grouped segment control to choose which style of table you want.
Table Sample
July7
Had a bit of an issue that took me a bit of head scratching. I had a UITableView which worked perfectly in iPhone API 2.2 but in 3.0 the insert/delete icons weren’t being displayed. Reworked and checked all the code but nothing worked.
It seems if you set the editing flag to YES when creating the tableViewCell’s, the insert/delete icon applied by the table delegate (editingStyleForRowAtIndexPath) isn’t displayed. Removing the call to cell.editing seems to fix the problem. This seems to be one of those things that is slightly different between iPhone OS 2.2 and 3.0.
January14
I was receiving the following error while trying to run my unit tests from XCode:
Test Host –path to app– exited abnormally with code 138
For whatever reason, removing the tests from the Unit Tests target and re adding them to the target made the error go away. No other changes necessary.
December30
Here is the article that explains how to add unit testing to XCode 3 project.
http://developer.apple.com/mac/articles/tools/unittestingwithxcode3.html
If you search for unit testing with XCode you will find a lot of older articles pointing to XCode 2.x and how to install etc, etc. Now XCode 3 includes unit testing out of the box, so it is a lot simpler.
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.
September23
Recently I did a presentation at the Melbourne Cocoahead, and recorded the screencast.
Here is the first part, a 24 minute demonstration of adding sparkle to a cocoa application.
The next 2 parts will hopefully be added in the next couple of weeks.
May17
Just another update NSTableView and creating it dynamically. If the NSTableView has its frame set then column resizing and scrolling seems to be screwed up.
By setting the frame of the scrollview and simply just calling init the NSTableView then the table seems to work correctly.
[tags]Cocoa[/tags]
May16
If you need to add a NSTableView to a window or view in your code then it is not immediately obvious how to do this.
For example adding a button, all you need to do is initWithFrame for the button, then add the button to the main view.
However a NSTableView isn’t that simple. When you drag one out using interface builder you are getting a NSTableView wrapped up in a ScrollView. If you try to add the same way you would an NSButton you can’t see anything. What is needed is a ScrollView to wrap up the tableview.
I found this code which outlines how to setup a NSTableView. It is on the excellent cocoadev web site.
[tags]Cocoa, NSTableView, CocoaDev[/tags]