ラベルにテキストを追加しようとしています。テキストがセルの指定された高さよりも大きくなると。細胞もその高さを成長させたいです。ラベルの高さを処理するために次のコードを追加しましたが、それをセルに伝播する方法もわかりません。
コード
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.navigationItem.title = @"Scribbles";
//Array
Scribble *scribble1 = [Scribble new];
[scribble1 setTitle:@"Test 1" andBody:@"This is fun! This is fun! This is fun! This is fun! This is fun! This is fun! This is fun! This is fun! This is fun! This is fun! This is fun!" andImage:@"scribble.png"];
Scribble *scribble2 = [Scribble new];
[scribble2 setTitle:@"Test 2" andBody:@"This is fun!" andImage:@"scribble2.png"];
Scribble *scribble3 = [Scribble new];
[scribble3 setTitle:@"Test 3" andBody:@"This is fun!" andImage:@"scribble3.png"];
Scribble *scribble4 = [Scribble new];
[scribble4 setTitle:@"Test 4" andBody:@"This is fun!" andImage:@"scribble.png"];
Scribble *scribble5 = [Scribble new];
[scribble5 setTitle:@"Test 5" andBody:@"This is fun!" andImage:@"scribble2.png"];
Scribble *scribble6 = [Scribble new];
[scribble6 setTitle:@"Test 6" andBody:@"This is fun!" andImage:@"scribble3.png"];
Scribble *scribble7 = [Scribble new];
[scribble7 setTitle:@"Test 7" andBody:@"This is fun!" andImage:@"scribble.png"];
Scribble *scribble8 = [Scribble new];
[scribble8 setTitle:@"Test 8" andBody:@"This is fun!" andImage:@"scribble3.png"];
scribbles = [NSArray arrayWithObjects:
scribble1,scribble2,scribble3,scribble4,scribble5,scribble6,scribble7,scribble8, nil];
}
//To make the Selection disappear
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self.tableView deselectRowAtIndexPath:[self.tableView indexPathForSelectedRow] animated:YES];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return scribbles.count;
}
//Loading stuff into tableView
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"ScribbleCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil){
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
Scribble *scribble = [scribbles objectAtIndex:indexPath.row];
UIImageView *scribbleImageView = (UIImageView *)[cell viewWithTag:100];
scribbleImageView.image = [UIImage imageNamed:scribble.image];
scribbleImageView.layer.cornerRadius = 18.0;
scribbleImageView.clipsToBounds = YES;
UILabel *scribbleNameLabel = (UILabel *)[cell viewWithTag:101];
scribbleNameLabel.text = scribble.title;
UILabel *scribbleBodyLabel = (UILabel *)[cell viewWithTag:102];
[scribbleBodyLabel setLineBreakMode:NSLineBreakByWordWrapping];
scribbleBodyLabel.numberOfLines = 0;
scribbleBodyLabel.text = scribble.body;
[scribbleBodyLabel sizeToFit];
return cell;
}