# Import "ViewController. h"
@ Interface ViewController ()
{
UITableView * _ table;
NSMutableArray * _ dataList;
UIView * footView;
}
@ End
@ Implementation ViewController
-(Void) viewDidLoad
{
[Super viewDidLoad];
_ Table = [[UITableView alloc] initWithFrame: CGRectMake (0, 0, self. view. frame. size. width, self. view. frame. size. height)];
_ Table. delegate = self;
_ Table. dataSource = self;
// _ Table. multipleTouchEnabled = YES;
[Self. view addSubview: _ table];
_ DataList = [[NSMutableArray alloc] initWithObjects: @ "1111n111n111n111n", @ "222", @ "333", @ "444", @ "555", @ "666 ", @ "777", nil];
FootView = [[UIView alloc] initWithFrame: CGRectMake (0, 0,320, 80)];
FootView. backgroundColor = [UIColor yellowColor];
_ Table. tableFooterView = footView;
}
-(Void) didReceiveMemoryWarning
{
[Super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
# Pragma mark-UITableView
-(NSInteger) numberOfSectionsInTableView :( UITableView *) tableView
{
Return 1;
}
-(NSInteger) tableView :( UITableView *) tableView numberOfRowsInSection :( NSInteger) section
{
Return [_ dataList count];
}
-(UITableViewCell *) tableView :( UITableView *) tableView cellForRowAtIndexPath :( NSIndexPath *) indexPath {
Static NSString * CellIdentifier = @ "Cell ";
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier: CellIdentifier];
If (cell = nil ){
Cell = [[UITableViewCell alloc] initWithStyle: UITableViewCellStyleDefault reuseIdentifier: CellIdentifier];
UILabel * label = [[UILabel alloc] initWithFrame: CGRectZero];
Label. tag = 1;
// Label. lineBreakMode = UILineBreakModeCharacterWrap;
Label. lineBreakMode = NSLineBreakByCharWrapping;
Label. highlightedTextColor = [UIColor whiteColor];
Label. numberOfLines = 0;
Label. opaque = NO; // If Opaque is selected, NO content behind the view should be drawn.
Label. backgroundColor = [UIColor clearColor];
[Cell. contentView addSubview: label];
}
UILabel * label = (UILabel *) [cell viewWithTag: 1];
NSString * text;
Text = [_ dataList objectAtIndex: indexPath. row];
CGRect cellFrame = [cell frame];
CellFrame. origin = CGPointMake (0, 0 );
Label. text = text;
CGRect rect = CGRectInset (cellFrame, 2, 2 );
Label. frame = rect;
[Label sizeToFit];
If (label. frame. size. height> 46 ){
CellFrame. size. height = 50 + label. frame. size. height-46;
}
Else {
CellFrame. size. height = 50;
}
[Cell setFrame: cellFrame];
Return cell;
}
-(CGFloat) tableView :( UITableView *) tableView heightForRowAtIndexPath :( NSIndexPath *) indexPath
{
UITableViewCell * cell = [self tableView: tableView cellForRowAtIndexPath: indexPath];
Return cell. frame. size. height;
}
@ End