这是您的问题的解决方案。
//
// CustomCell.m
// Custom
//
// Created by Syed Arsalan Pervez on 2/8/13.
// Copyright (c) 2013 SAPLogix. All rights reserved.
//
#import "CustomCell.h"
@implementation CustomCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
_textView = [[UITextView alloc] initWithFrame:CGRectZero];
[_textView setBackgroundColor:[UIColor clearColor]];
[_textView setContentInset:UIEdgeInsetsMake(0, 0, 0, 0)];
[[self contentView] addSubview:_textView];
}
return self;
}
- (void)layoutSubviews
{
[super layoutSubviews];
[_textView setFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
}
- (void)dealloc
{
[_textView release];
[super dealloc];
}
@end
使用细胞。
//
// TestViewController.m
// Custom
//
// Created by Syed Arsalan Pervez on 2/8/13.
// Copyright (c) 2013 SAPLogix. All rights reserved.
//
#import "TestViewController.h"
#import "CustomCell.h"
@interface TestViewController ()
@end
@implementation TestViewController
- (void)viewDidLoad
{
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 2;
}
#define DEFAULT_TEXT @"This is an example block of text which seems to run over the edge of the UITableView so it no longer shows up the way I want."
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *_identifier = @"CustomCell";
CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:_identifier];
if (!cell)
{
cell = [[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:_identifier];
[[cell contentView] setBackgroundColor:[UIColor redColor]];
}
cell.textView.text = DEFAULT_TEXT;
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
CGRect frame = [[UIApplication sharedApplication] statusBarFrame];
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
// You can replace DEFAULT_TEXT with text you want to be displayed in the cell.
CGSize size = [DEFAULT_TEXT sizeWithFont:[UIFont systemFontOfSize:13] constrainedToSize:CGSizeMake( UIInterfaceOrientationIsPortrait(orientation) ? frame.size.width : frame.size.height, 9999)];
return size.height;
}
- (UIInterfaceOrientation)interfaceOrientation
{
return (UIInterfaceOrientation)UIInterfaceOrientationMaskAll;
}
- (void)dealloc
{
[super dealloc];
}
@end