I am trying to fix someone's code, and I ran into a problem. Here is the situation: I have a fullscreen UIViewController with a bottom bar button. When I click this button, it shows the popup controller in the lower left corner of the screen. This view controller inside the popup also has a button, and when I press the THAT button, it pushes the new view controller into my popup. This new view controller is a UITableView that can have a number of elements. The problem is that when I try to scroll down to see some elements off the screen, the scroll returns to the first position in the table, that is, it really does not scroll.
More specifically, the code is here:
In FullScreenVC.h:
@property (nonatomic, retain) NSMutableArray* stuffInList; @property (nonatomic, retain) UIPopoverController *namePopover; @property (nonatomic, retain) UINavigationController *nameNav; @property (nonatomic, retain) UIBarButtonItem* addButton;
Inside FullScreenVC buttonPressed (called when addButton is pressed):
FirstPopupVC *vc=[FirstPopupVC alloc] initWithNibName@ "FirstPopupVC" bundle:nil]; vc.delegate=self; vc.stuffInList=self.stuffInList; // This is just the NSArray of list items self.nameNav = [[[UINavigationController alloc] initWithRootViewController:vc] autorelease]; self.namePopover = [[[UIPopoverController alloc] initWithContentViewController:self.nameNav] autorelease]; [vc release]; [self.namePopover presentPopoverFromBarButtonItem:self.addButton permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
In other words, the FirstPopupVC vc object is the root view controller for the name UINavigationViewControllerNav, and nameNav is the navigation controller that is the content inside the namePopover UIPopoverController. I think the last line launches FirstPopupVC as a popup from addButton. Also note that the XIB file FirstPopupVC.xib is a simple NIB file that contains several simple views (shortcut, etc.) And a small button that the user can click to get a second pop-up window, as we will see.
Inside FirstPopupVC we have:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // some other irrelevant initialization stuff here ... self.contentSizeForViewInPopover = CGSizeMake(320, 340); } return self; } -(void)littleButtonClicked:(id)sender { SecondPopupVC * secondVC=[[SecondPopupVC alloc] initWithNibName:"@SimpleTableView" bundle"nil]; secondVC.delegate=self; secondVC.stuffInList=self.stuffInList; [self.navigationController pushViewController:secondVC animated:YES]; [secondVC release]; }
This, of course, is the second view controller inside the popop.
Inside SecondPopupVC we have:
- (id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { self.contentSizeForViewInPopover = CGSizeMake(320, 340); } return self; }
Obviously, calling contentSizeForViewInPopover here sets the size of the popover view as a table. It looks like this is called inside initWithNibName in both the first and second view controllers.
So the problem is if my listOfStuff is big, i.e. if the set of elements in the table is large, then the table will not scroll outside the first visible rowset. I can scroll down to see these elements, but as soon as I release the mouse pointer (on the emulator) or my finger (on the device), it bounces back to the top of the list.
I tried to add autoresizingmak code, as discussed in the table view in popover does not scroll , but it did not work for me.
So, how can I fix the above code so that my table stays scrolled when I try to scroll it?