SplitViewController BUG?

I created a very simple iOS project splitView Controller that has a very strange error. If you run the application in landscape mode, press the button to open another image, rotate it to the portrait and return to the initial view - the table menu on the left should not be visible, but it .. Oddly enough, you cannot interact with it, which makes me believe that this is actually not some kind of artifact.

Please note that this only happens the first time you do this, and then never again until you start the application in landscape.

MasterViewController:

#import "MasterViewController.h" #import "DetailViewController.h" @interface MasterViewController () { NSMutableArray *_objects; } @property (nonatomic, strong)UITableView *menu; @end @implementation MasterViewController - (void)awakeFromNib { self.clearsSelectionOnViewWillAppear = NO; self.contentSizeForViewInPopover = CGSizeMake(320.0, 600.0); [super awakeFromNib]; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. self.navigationItem.leftBarButtonItem = self.editButtonItem; UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(insertNewObject:)]; self.navigationItem.rightBarButtonItem = addButton; self.detailViewController = (DetailViewController *)[[self.splitViewController.viewControllers lastObject] topViewController]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (void)insertNewObject:(id)sender { if (!_objects) { _objects = [[NSMutableArray alloc] init]; } [_objects insertObject:[NSDate date] atIndex:0]; NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0]; [self.tableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic]; } #pragma mark - Table View - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return _objects.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath]; NSDate *object = _objects[indexPath.row]; cell.textLabel.text = [object description]; return cell; } - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { // Return NO if you do not want the specified item to be editable. return YES; } - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { if (editingStyle == UITableViewCellEditingStyleDelete) { [_objects removeObjectAtIndex:indexPath.row]; [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade]; } else if (editingStyle == UITableViewCellEditingStyleInsert) { // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view. } } /* // Override to support rearranging the table view. - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath { } */ /* // Override to support conditional rearranging of the table view. - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath { // Return NO if you do not want the item to be re-orderable. return YES; } */ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSDate *object = _objects[indexPath.row]; self.detailViewController.detailItem = object; } @end 

DetailViewController:

 #import "DetailViewController.h" #import "StandardViewViewController.h" @interface DetailViewController () @property (strong, nonatomic) UIPopoverController *masterPopoverController; -(IBAction)buttonTapped:(id)sender; - (void)configureView; @end @implementation DetailViewController #pragma mark - Managing the detail item - (void)setDetailItem:(id)newDetailItem { if (_detailItem != newDetailItem) { _detailItem = newDetailItem; // Update the view. [self configureView]; } if (self.masterPopoverController != nil) { [self.masterPopoverController dismissPopoverAnimated:YES]; } } - (void)configureView { // Update the user interface for the detail item. if (self.detailItem) { self.detailDescriptionLabel.text = [self.detailItem description]; } } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. [self configureView]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } #pragma mark - Split view - (void)splitViewController:(UISplitViewController *)splitController willHideViewController:(UIViewController *)viewController withBarButtonItem:(UIBarButtonItem *)barButtonItem forPopoverController:(UIPopoverController *)popoverController { barButtonItem.title = NSLocalizedString(@"Master", @"Master"); [self.navigationItem setLeftBarButtonItem:barButtonItem animated:YES]; self.masterPopoverController = popoverController; } - (void)splitViewController:(UISplitViewController *)splitController willShowViewController:(UIViewController *)viewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem { // Called when the view is shown again in the split view, invalidating the button and popover controller. [self.navigationItem setLeftBarButtonItem:nil animated:YES]; self.masterPopoverController = nil; } -(IBAction)buttonTapped:(id)sender { StandardViewViewController *sv = [[StandardViewViewController alloc]initWithNibName:@"StandardViewViewController" bundle:nil]; [self.splitViewController presentViewController:sv animated:YES completion:nil]; } @end 

Is this a known bug? is there any solution

+4
source share
1 answer

Probably not very, the proposed solution works here . Here's how you could implement the solution:

 -(IBAction)buttonTapped:(id)sender { StandardViewViewController *sv = [[StandardViewViewController alloc] initWithNibName:nil bundle:nil]; sv.modalPresentationStyle = UIModalPresentationPageSheet; // <-- Add this [self.splitViewController presentViewController:sv animated:YES completion:nil]; } 

In StandardViewController.m add this:

 -(void)viewWillLayoutSubviews { self.view.bounds = [StandardViewViewController screenBoundsForCurrentOrientation]; [super viewWillLayoutSubviews]; } +(CGRect)screenBoundsForCurrentOrientation { return [self screenBoundsForOrientation:[UIApplication sharedApplication].statusBarOrientation]; } +(CGRect)screenBoundsForOrientation:(UIInterfaceOrientation)orientation { UIScreen *screen = [UIScreen mainScreen]; CGRect fullScreenRect = screen.bounds; //implicitly in Portrait orientation. if(orientation == UIInterfaceOrientationLandscapeRight || orientation == UIInterfaceOrientationLandscapeLeft){ CGRect temp = CGRectZero; temp.size.width = fullScreenRect.size.height; temp.size.height = fullScreenRect.size.width; fullScreenRect = temp; } return fullScreenRect; } 

To make it more beautiful, you can put the code for the standard monitor in a new class that can extend the StandardViewController.

And yes, it looks like a mistake.

+1
source

All Articles