I want when tab on row a UIView containing two button appear at the center of the cell, so I did the following code
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
//how can I get the text of the cell here?
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
UIView *v = [[UIView alloc] init];
v.center = cell.center;
UIButton*button1 =[[UIButton alloc] init];
button1.frame = CGRectMake(v.center.x - 5 , v.center.y , 5 , v.center.y + 4 );
button1.titleLabel.text = @"I'm label 1";
[v addSubview: button1];
UIButton*button2 =[[UIButton alloc] init];
button2.frame = CGRectMake(v.center.x - + 1 , v.center.y , 5 , v.center.y + 4 );
button2.titleLabel.text = @"I'm label 2";
[v addSubview: button2];
[cell addSubview:v];
/*
<#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
// ...
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
*/
}
UIView doesn’t appear. How to solve that?
initWithFrameis the designated initialiser for views.Since you are using
initit doesn’t know how large a view to create.Also
UIButton *button1 = [[UIButton alloc] init];is incorrect. UIButtons are created with thebuttonWithType:class method.