2

I am adding the following codes to add a footer with a button to perform an action. i am not able to re-size the button to the size of the cell. The change in the CGRectMake(0, 0, 300,44) value is not affecting the change of the footer appears can any one help me. I am using a table having more session. i don't want a footer for every session instead i need at the end of the table so i inserted the following code.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath   
*)indexPath 
{
//...
footerView  = [[UIView alloc] init];

UIButton* Logoutbutton = [UIButton buttonWithType:UIButtonTypeCustom];

[Logoutbutton setTitle:@"Logout" forState:UIControlStateNormal];

NSLog(@"cell width : %d",cell.contentView.frame.size.width);
[Logoutbutton setFrame:CGRectMake(0, 0, 300,44)];
[Logoutbutton setBackgroundImage:[UIImage imageNamed:@"LogoutBgImage.png"] 
forState:UIControlStateNormal];
[Logoutbutton setBackgroundColor:[UIColor clearColor]]; 

[Logoutbutton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; 
[Logoutbutton addTarget:self action:@selector(LogoutbuttonPressed:) 
forControlEvents:UIControlEventTouchUpInside];

Settingstable.tableFooterView = Logoutbutton;

return cell;
}

- (void)LogoutbuttonPressed: (UIButton*) button
{
 //some action
}

Can any one help me to fix this issue

Rui Peres
  • 25,741
  • 9
  • 87
  • 137
rashii
  • 500
  • 7
  • 17

3 Answers3

2

You Don't need to add a button to uitableview , instead add it to the footer of the tableview for which you will have to pass a view to the delegate method of tableview :-

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section

You may read this tutorial as it has same requirement as yours.enter image description here

Abhishek Singh
  • 6,068
  • 1
  • 23
  • 25
0

use this way for footer of tableview

self.tableView.tableFooterView = myCustomFooterView

and for footer view of whole table,use

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section

and read more about it here

http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UITableViewDelegate_Protocol/Reference/Reference.html

and if you wan't footer of only one cell, then implement a custom cell, and use layoutsubviews to change the cell settings, for custom cell use this link

http://www.e-string.com/content/custom-uitableviewcells-interface-builder

http://www.galloway.me.uk/tutorials/custom-uitableviewcell/

http://cocoawithlove.com/2009/04/easy-custom-uitableview-drawing.html

mattjgalloway
  • 34,792
  • 12
  • 100
  • 110
Saad
  • 8,857
  • 2
  • 41
  • 51
  • this created footer for each session right . I need only one singe footer display at the end of the last row in my UITable view – rashii May 11 '12 at 13:45
  • yea i added a button to a custom view and assigned it to footer but now what happened is the function action for button is not being called when clicked – rashii May 11 '12 at 14:08
  • see the xib connection to the button, that may be removed – Saad May 11 '12 at 14:13
  • oops i am not using xib. its the @selector which calls the action – rashii May 11 '12 at 14:23
  • huh, then it must call the function, clean ur prjct – Saad May 11 '12 at 14:28
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/11153/discussion-between-rashii-and-the-saad) – rashii May 11 '12 at 14:31
0

To give the footer view height use this delegate method:

(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
Tisho
  • 8,320
  • 6
  • 44
  • 52
Nims
  • 431
  • 6
  • 15