Problems with TableView inside a UIViewController

Discussion in 'iOS Programming' started by onklen, Oct 19, 2010.

  1. onklen macrumors newbie

    Joined:
    Oct 19, 2010
    #1
    I'm fairly new to iPhone programmer but hope someone can answer this simple questions.

    I have pushed a new UIViewController which has a TableView.

    My .h file looks like this:

    Code:
    @interface SetUpGameViewController : UIViewController {
    	
    	UITableView *tableView;
    	NSMutableArray *array;
    }
    
    @property (retain, nonatomic) UITableView *tableView;
    @property (nonatomic, retain) NSMutableArray *array;
    
    @end 
    I then have two problems when pushing this UIViewController on the stack.

    I use a .nib file but even though I have made the tableview only fill half the size of the screen from IB it seems to fill out the whole screen in iPhone simulator. Why is that?

    Another problem is that I want to push a new UIViewController from this TableView. I do that with this code:


    Code:
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
        // Navigation logic -- create and push a new view controller
    	
    	[self.tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    	if ([[array objectAtIndex:indexPath.row] isEqual:@"Set up players"])
    	{
    		SetUpGameViewController *set_up_players = [[SetUpGameViewController alloc] initWithNibName:@"PlayerSettingsViewController" bundle:Nil];
    		[self.navigationController pushViewController:set_up_players animated:YES];
    		[set_up_players release];
    	}
    	
    }

    My problem is that the code line with :
    Code:
    deselectRowAtIndexPath
    does not seem to be working.
    When I return from the new UIViewController the row is still selected?

    Any help is highly appreciated

    Rolf
     
  2. newlearner macrumors member

    newlearner

    Joined:
    Jul 30, 2009
    Location:
    india
    #2
    In IB, have you set the delegate of tableview to SetUpGameViewController(File's Owner)? If the tableview instance in the code is not linked with the one in the .xib file, you will not get the required output.

    regarding your second issue, in the viewDidLoad method of your controller, use
    this property to remove the selections.

    Code:
    self.clearsSelectionOnViewWillAppear = YES;
     
  3. onklen thread starter macrumors newbie

    Joined:
    Oct 19, 2010
    #3
    I have the delegate of talbeView to SetUpGameViewController(File's Owner).
    I can easily input text to the different row and push new viewcontrollers when pressing the different rows. But the size of the tableView still fills the whole screen even though I made it only fill half the screen in IB.
    Don't really understand this. I though the layout of the view was solely determined by IB. So it would look exactly as laid out in IB.


    If I try to add the line of code in viewDidLoad I get the following error:

    error: request for member 'clearsSelectionOnViewWillAppear' in something not a structure or union



    Any other comments are very much appreciated
     
  4. onklen thread starter macrumors newbie

    Joined:
    Oct 19, 2010
    #4
    Got it fixed.

    Had the view mixed up in IB.
    Had the UiTableview pointing at the File's Owner's view. So it would always only show one view at the time.

    The second problem was due to me calling the UITableView *tableView.
    So when trying to call:

    Code:
    [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
    it made an error as it was called the same as the instance.

    So I changed the name to gameTableView and everything was working as a charm.

    Thx for the reply. Got me in the correct direction.
     

Share This Page