Welcome, Guest
Username Password: Remember me

Add UIButton in the TableViewCell
(1 viewing) (1) Guest

TOPIC: Add UIButton in the TableViewCell

Add UIButton in the TableViewCell 1 year, 8 months ago #1

How to Add UIButton in the TableViewCell?

I want label and button in one cell, button and image on second cell,
If user clicks button on first cell , it would take to another view to show scrollable page which contains lot of texts
and after he reads the text then user clicks navigation bar to goback to orginal screen.

On second cell the user clicks facebook login button and after he logs in and I'm pulling profile picture to display on the image view of the second cell. I'm not able to figure out by going through the sample code.

Can you help me on this and and some sample code would be appreciated?

Thanks,
raj
  • rajdn
  • OFFLINE
  • Senior Boarder
  • Posts: 47
  • Karma: 0

Re: Add UIButton in the TableViewCell 1 year, 8 months ago #2

You can simply use a normal SCTableViewCell and add any subviews you want to it:

 
...
SCTableViewCell *cell = [SCTableViewCell cell];
UIButton *myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
myButton.frame = myFrame; // myFrame is where you want to place the button in the cell
[cell addSubview:myButton];
//etc.
...
 


Alternatively, you can do the same thing in the tableViewModel:willConfigureCell:forRowAtIndexPath: method (usually if the cells are auto generated for you).

Please tell me if you need any more help with this.
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2404
  • Karma: 72

Re: Add UIButton in the TableViewCell 1 year, 7 months ago #3

I'm trying to add Submit Round Button to the SCTabelViewModel. I need to add this button after the text field area. How do I figure out the exact size and location of the cell that is after text field. Here is my code and screenshoot

Code
----
SCLabelCell *labelCell2 = [SCLabelCell cellWithText:@"Feedback & Suggetions" withBoundKey:nil withLabelTextValue:@"Feedback & Suggetions"];
SCTextFieldCell *feedbackTextFieldCell = [SCTextFieldCell cellWithText:nil withPlaceholder:@"Please enter Feedback & Suggetions"
withBoundKey:@"feedback" withTextFieldTextValue:nil];
feedbackTextFieldCell.valueRequired = TRUE;

SCTableViewCell *submitButtonCell = [SCTableViewCell cell];
UIButton *submitButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[submitButton setTitle:@"Submit" forState:UIControlStateNormal];

[submitButton addTarget:self action:@selector(buttonPushed:)
forControlEvents:UIControlEventTouchUpInside];

submitButton.frame = CGRectMake(9, 5,255, 45);
[submitButtonCell addSubview:submitButton];



SCLabelCell *labelCell3 = [SCLabelCell cellWithText:@"App Info3" withBoundKey:nil withLabelTextValue:@"iBasavanna App Info3"];



[section1 addCell:labelCell1];
[section2 addCell:labelCell2];
[section2 addCell:feedbackTextFieldCell];
[section2 addCell:submitButtonCell];
[section3 addCell:labelCell3];
button.jpg
  • rajdn
  • OFFLINE
  • Senior Boarder
  • Posts: 47
  • Karma: 0

Re: Add UIButton in the TableViewCell 1 year, 7 months ago #4

Hi Raj,

If you're working in portrait mode, a typical cell is usually 320x44 pixels. You don't need to find the location, you just set the frame of the button relative to the cell itself. At typical frame setting would be:

 
submitButton.frame = CGRectMake(20, 6, 280, 32);
 
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2404
  • Karma: 72

Re: Add UIButton in the TableViewCell 1 year, 7 months ago #5

Thanks for the quick reply
I tried with that code . But the button doesn't cover the full cell window. Also , How do I reduce the width of the cells?
button-20101021.jpg
  • rajdn
  • OFFLINE
  • Senior Boarder
  • Posts: 47
  • Karma: 0

Re: Add UIButton in the TableViewCell 1 year, 7 months ago #6

One idea to do that is to leave the button as it is and set the cell's backgroundColor property to [UIColor clearColor] (make it transparent).
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2404
  • Karma: 72
Time to create page: 0.95 seconds