Skip to main content

add uiview at row selection



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];

*/

}







the uiview doesn't appear any idea how to solve that





Best regards


Comments

  1. initWithFrame is the designated initialiser for views.

    Since you are using init it doesn't know how large a view to create.

    Also UIButton *button1 = [[UIButton alloc] init]; is incorrect. UIButtons are created with the buttonWithType: class method.

    ReplyDelete
  2. UIView *v = [[UIView alloc] init];//You have not set the frame of the v;

    ReplyDelete
  3. try:

    [cell.contentView addSubview: v];


    It should work.

    Edit:
    Try this code. Give the frames accordingly, it will work.

    UIView *v = [[UIView alloc] initWithFrame:CGRectMake(44, 100, 200, 200)];
    UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    button.frame = CGRectMake(0, 0, 50, 50);
    [v addSubview:button];

    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    [cell.contentView addSubview:v];

    ReplyDelete

Post a Comment

Popular posts from this blog

[韓日関係] 首相含む大幅な内閣改造の可能性…早ければ来月10日ごろ=韓国

div not scrolling properly with slimScroll plugin

I am using the slimScroll plugin for jQuery by Piotr Rochala Which is a great plugin for nice scrollbars on most browsers but I am stuck because I am using it for a chat box and whenever the user appends new text to the boxit does scroll using the .scrollTop() method however the plugin's scrollbar doesnt scroll with it and when the user wants to look though the chat history it will start scrolling from near the top. I have made a quick demo of my situation http://jsfiddle.net/DY9CT/2/ Does anyone know how to solve this problem?

Why does this javascript based printing cause Safari to refresh the page?

The page I am working on has a javascript function executed to print parts of the page. For some reason, printing in Safari, causes the window to somehow update. I say somehow, because it does not really refresh as in reload the page, but rather it starts the "rendering" of the page from start, i.e. scroll to top, flash animations start from 0, and so forth. The effect is reproduced by this fiddle: http://jsfiddle.net/fYmnB/ Clicking the print button and finishing or cancelling a print in Safari causes the screen to "go white" for a sec, which in my real website manifests itself as something "like" a reload. While running print button with, let's say, Firefox, just opens and closes the print dialogue without affecting the fiddle page in any way. Is there something with my way of calling the browsers print method that causes this, or how can it be explained - and preferably, avoided? P.S.: On my real site the same occurs with Chrome. In the ex