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.
June28
I needed to search for files with a common bit of content on a host that I had connected to ssh.
This example searches all php files for ‘Search Term’, it search every sub directory from the current directory and prints out the name:
find . -name "*.php" -exec grep -l "Search Term" {} \;
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
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]
May10
I have a number of projects that use Microsoft’s Enterprise Library, but usually they use Integrated Security to connect to the SQL Server. Yesterday I had a project which had to connect to a SQL Server via username and password and found it wasn’t the easiest to work out how the dataconfiguration file should be set up. This is what I came up with that worked:
<connectionstring name="Sql Connection String">
<parameters>
<parameter name="Data Source" value="Server" isSensitive="false" />
<parameter name="Initial Catalog" value="Database" isSensitive="false" />
<parameter name="Integrated Security" value="false" isSensitive="false" />
<parameter name="Connection Timeout" value="10" isSensitive="false" />
<parameter name="user" value="sa" isSensitive="false" />
<parameter name="password" value="sa" isSensitive="false" />
</parameters>
</connectionstring>
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