change the content of table footer view while running

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

  1. AbhishekApple macrumors member

    Joined:
    Aug 5, 2010
    #1
    how to change the content of table footer view while running

    I want to toggle the buttons in viewForFooterInsection

    i.e call the

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

    Code:
    
    - (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];
    				favourite=1;
    				[tbldetail reloadData];
    			}
    			else {
    				[button setTitle:@"Remove From Favorites" forState:UIControlStateNormal];
    				[button addTarget:self action:@selector(removeFav:) forControlEvents:UIControlEventTouchUpInside];
    				favourite=0;
    			}
    			[footerView addSubview:button];
    }
    return footerView;
    }
    
     
  2. cnstoll macrumors 6502

    Joined:
    Aug 29, 2010
    #2
    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

    Joined:
    Aug 5, 2010
    #3
    "setNeedsDisplay"....
    Thanks
     

Share This Page