//
// DynamicHeightsViewController. h
// DynamicHeights
//
// Created by Matt Long on 9/22/09.
// Copyright Skye Road Systems, Inc. 2009. All rights reserved.
//
# Import <UIKit/UIKit. h>
@ Interface DynamicHeightsViewController: UIViewController {
IBOutlet UITableView * dataTableView;
NSMutableArray * items;
}
@ End
//////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// ////////////////////////////////////////
//
// DynamicHeightsViewController. m
// DynamicHeights
//
// Created by Matt Long on 9/22/09.
// Copyright Skye Road Systems, Inc. 2009. All rights reserved.
//
# Import "DynamicHeightsViewController. h"
# Define FONT_SIZE 14.0f
# Define CELL_CONTENT_WIDTH 3200000f
# Define CELL_CONTENT_MARGIN 10.0f
@ Implementation DynamicHeightsViewController
-(Void) viewDidLoad {
[SuperviewDidLoad];
Items = [[NSMutableArrayalloc] init];
[ItemsaddObject: @ "After two years in Washington, I often long for the realism and sincerity of Hollywood. \ n \ t-Fred Thompson, speech before the Commonwealth Club of Californiaaaagdd whether the male regulates the male and whether the male regulates whether the male and the male are ll "];
[ItemsaddObject: @ "It is a profitable thing, if one is wise, to seem foolish. \ n \ t-Aeschylus (525 BC-456 BC)"];
[ItemsaddObject: @ "Bill Gates is a very rich man today... and do you want to know why? The answer is one word: versions. \ n \ t-Dave Barry "];
[ItemsaddObject: @ "At the worst, a house unkept cannot be so distressing as a life unlived. \ n \ t-Dame Rose Macaulay (1881-1958) "];
[ItemsaddObject: @ "It is curious that physical courage shoshould be so common in the world and moral courage so rare. \ n \ t-Mark Twain (1835-1910) "];
[ItemsaddObject: @ "The knowledge of the world is only to be acquired in the world, and not in a closet. \ n \ t-Lord Chesterfield (1694-1773), Letters to His Son, 1746, published 1774 "];
[ItemsaddObject: @ "What lies behind us and what lies before us are tiny matters compared to what lies within us. \ n \ t-Ralph Waldo Emerson (1803-1882), (attributed) "];
}
-(Void) dealloc {
[Items release], items = nil;
[Super dealloc];
}
# Pragma mark-
# Pragma mark UITableView Delegaates
-(NSInteger) tableView :( UITableView *) tableView numberOfRowsInSection :( NSInteger) section
{
Return [itemscount];
}
-(NSInteger) numberOfSectionsInTableView :( UITableView *) tableView;
{
Return 1;
}
-(CGFloat) tableView :( UITableView *) tableView heightForRowAtIndexPath :( NSIndexPath *) indexPath;
{
NSString * text = [itemsobjectAtIndex: [indexPath row];
CGSize constraint = CGSizeMake (CELL_CONTENT_WIDTH-(CELL_CONTENT_MARGIN * 2), 20000.0f );
CGSize size = [textsizeWithFont: [UIFontsystemFontOfSize: FONT_SIZE] constrainedToSize: constraint lineBreakMode: UILineBreakModeWordWrap];
CGFloat height = MAX (size. height, 44.0f );
Return height + (CELL_CONTENT_MARGIN * 2 );
}
-(UITableViewCell *) tableView :( UITableView *) TV cellForRowAtIndexPath :( NSIndexPath *) indexPath
{
UITableViewCell * cell;
UILabel * label = nil;
Cell = [TV dequeueReusableCellWithIdentifier: @ "Cell"];
If (cell = nil)
{
Cell = [[[UITableViewCellalloc] initWithFrame: CGRectZeroreuseIdentifier: @ "Cell"] autorelease];
Label = [[UILabel alloc] initWithFrame: CGRectZero];
[Label setLineBreakMode: UILineBreakModeWordWrap];
[Label setMinimumFontSize: FONT_SIZE];
[Label setNumberOfLines: 0];
[Label setFont: [UIFontsystemFontOfSize: FONT_SIZE];
[Label setTag: 1];
[[Label layer] setBorderWidth: 2.0f];
[[Cell contentView] addSubview: label];
}
NSString * text = [itemsobjectAtIndex: [indexPath row];
CGSize constraint = CGSizeMake (CELL_CONTENT_WIDTH-(CELL_CONTENT_MARGIN * 2), 20000.0f );
CGSize size = [textsizeWithFont: [UIFontsystemFontOfSize: FONT_SIZE] constrainedToSize: constraint lineBreakMode: UILineBreakModeWordWrap];
If (! Label)
Label = (UILabel *) [cell viewWithTag: 1];
[Label setText: text];
[Label setFrame: CGRectMake (CELL_CONTENT_MARGIN, CELL_CONTENT_MARGIN, CELL_CONTENT_WIDTH-(CELL_CONTENT_MARGIN * 2), MAX (size. height, 44.0f)];
Return cell;
}