uisplitviewcontroller – SplitViewController BUG?

uisplitviewcontroller – SplitViewController BUG?,第1张

概述我设置了一个非常简单的iOS splitView Controller项目,它有一个非常奇怪的bug.如果你以横向模式启动应用程序,单击按钮打开另一个视图,旋转到纵向,然后返回到起始视图 – 左边的表格菜单不应该是可见的但它是..很奇怪你不能与它互动,这让我相信它不是真的存在,而是某种神器. 请注意,这只会在您第一次执行此 *** 作时再次发生,直到您在横向上启动应用程序. MasterViewContr 我设置了一个非常简单的iOS splitVIEw Controller项目,它有一个非常奇怪的BUG.如果你以横向模式启动应用程序,单击按钮打开另一个视图,旋转到纵向,然后返回到起始视图 – 左边的表格菜单不应该是可见的但它是..很奇怪你不能与它互动,这让我相信它不是真的存在,而是某种神器.

请注意,这只会在您第一次执行此 *** 作时再次发生,直到您在横向上启动应用程序.

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

这是一个已知的错误?有解决方案吗?

解决方法 尽管不是很漂亮,但该解决方案建议使用 here.
这是您实现解决方案的方式:

-(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];}

在StandardVIEwController.m中添加:

-(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;}

为了使它更漂亮,您可以将StandardVIEwController的代码放入StandardVIEwController可以扩展的新类中.

而且,是的,这看起来像一个错误.

总结

以上是内存溢出为你收集整理的uisplitviewcontroller – SplitViewController BUG?全部内容,希望文章能够帮你解决uisplitviewcontroller – SplitViewController BUG?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1079332.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存