change the content of table footer view while running

Discussion in 'iOS Programming' started by AbhishekApple, Feb 9, 2011.

  1. AbhishekApple macrumors member

    Aug 5, 2010
    how to change the content of table footer view while running

    I want to toggle the buttons in viewForFooterInsection

    i.e call the

    - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
    function again on button click.

    - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    		if(footerView == nil) {
    			//allocate the view if it doesn't exist yet
    			footerView  = [[UIView alloc] init];
    	UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    			if (!favourite) {
    				[button setTitle:@"Add to Favorites" forState:UIControlStateNormal];
    				[button addTarget:self action:@selector(addFav:) forControlEvents:UIControlEventTouchUpInside];
    				[tbldetail reloadData];
    			else {
    				[button setTitle:@"Remove From Favorites" forState:UIControlStateNormal];
    				[button addTarget:self action:@selector(removeFav:) forControlEvents:UIControlEventTouchUpInside];
    			[footerView addSubview:button];
    return footerView;
  2. cnstoll macrumors 6502

    Aug 29, 2010
    You just need to keep a reference to the view object that you put in the footer. Then when the button gets pressed call a selector that will change the contents of the view, just like you've done. Finally call "setNeedsDisplay" on the view. That way the view will be re-drawn with your changes.
  3. AbhishekApple thread starter macrumors member

    Aug 5, 2010

Share This Page