从didSelectRowAtIndexPath iOS 10

时间:2016-10-05 09:57:38

标签: objective-c ios10 didselectrowatindexpath addsubview

我遇到了问题:

我的iPad的主页分为两个视图。

1-st - menu(UITableView)(左侧);

2-nd - 工作区(UIViewController),我改变了UIView(右侧)。

应用程序可以工作,看起来像一个普通的社交网页。

AppDelegate.m

首先,我为工作区初始化我的UIViewControllers并将它们添加到数组中。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];

    NSMutableArray *vcs = [NSMutableArray array];

    FriendsForImport *friendsForImport = [[CoreDataHelper helperCoreDataHelper] getSocialAccountInfoByIdSocial:0 withUid:@"myUid"];

    SocialPageViewController *socialPageViewController = [[SocialPageViewController alloc] initWithIdSocial:0 withFriendsForImport:friendsForImport withMyAccount:1];

    UINavigationController *socialPageNavigationController = [[UINavigationController alloc] initWithRootViewController:socialPageViewController];

    NSDictionary *socialPageNavigationControllerDict0 = [NSDictionary dictionaryWithObjectsAndKeys:socialPageNavigationController, @"vc", [NSString stringWithFormat:NSLocalizedString(@"MainMenuMyPageViewController", nil)], @"title", @"111-user.png", @"image", @"1", @"notification", @"0", @"idSocial",nil];

    [vcs addObject:socialPageNavigationControllerDict0];

        .....init and add to array another......

    Below In this method I init main UIViewController (**iPadSHSidebarViewController**) with UIViewControllers array.

    _sidebariPad = [[iPadSHSidebarViewController alloc] initWithArrayOfVC:vcs];
            self.window.rootViewController = _sidebariPad;
}

在主UIViewController中 的 iPadSHSidebarViewController.m

- (void)viewDidLoad
{
     //init work area
     _mainViewController = [[UIViewController alloc] init];

     //init menu
     _menuView=[[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width*ksliderMenuWidthKoeff, self.view.frame.size.height)];
     [self.view addSubview:_menuView];
        .....
     //set to work area first UIViewController from array (SocialPageViewController)
     [self changeMain:[[viewsArray objectAtIndex:0] objectForKey:@"vc"]];
}

// for changing UIViewControllers in work area
-(void)changeMain:(UIViewController *)main
{
     [_mainViewController.view removeFromSuperview];
     _mainViewController = main;
     _mainViewController.view.frame=CGRectMake(_menuView.frame.size.width, 0, self.view.frame.size.width-_menuView.frame.size.width, self.view.frame.size.height);
     [self.view addSubview:_mainViewController.view];   
}

// for opening selected user's page UIViewControllers in work area above all opened UIViewControllers

-(void)setModalInMain:(UIViewController *)modal
{
     modal.view.tag=countTag++; 
     [_mainViewController.view addSubview:modal.view];
}

SocialPageViewController 是用户的页面,它首先是我们在app init时在工作区看到的内容。

SocialPageViewController 获得了一个带有好友列表的UIViewTable。 当用户点击好友列表中的行时,使用工作区的UIViewControler(iPadSHSidebarViewController)方法 setModalInMain ,使用所选用户的数据初始化新的UIViewControler。

SocialPageViewController.m

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    FriendsForImport *friendsForImport = [_listArrayForOut objectAtIndex:indexPath.row];

    if([friendsForImport.active intValue]==1){

        SocialPageViewController *socialPageViewController = [[SocialPageViewController alloc] initWithIdSocial:_idSocial withFriendsForImport:friendsForImport withMyAccount:0];
        socialPageViewController.delegate=self;
        UINavigationController *socialPageNavigationController = [[UINavigationController alloc] initWithRootViewController:socialPageViewController];

        iPadSHSidebarViewController *ipadSHSidebarViewController=(iPadSHSidebarViewController*)XAppDelegate.window.rootViewController;
        [ipadSHSidebarViewController setModalInMain: socialPageNavigationController];
    }
}

在iPhone( iOS8,10 )中,一切正常。

在iPad( iOS8 )中,一切正常

屏幕截图#1

但是在 iOS 10 中 - 当我点击该行而不是用户的数据页时,会打开带有白色导航栏的空 UIViewController

(但如果在IOS 10中我尝试在其他地方执行此操作(点击导航栏按钮) - 一切正常)。

屏幕截图#2

如果我在没有导航栏的情况下尝试从 didSelectRowAtIndexPath 打开页面 - 一切正常。但页面打开时没有导航栏。

屏幕截图#3

为什么会在iOS10和didSelectRowAtIndexPath方法中发生这种情况?

If I try open page from didSelectRowAtIndexPath without navigationbar - all work fine. But page open without navigationbar.

First what user see in work area when app init is **SocialPageViewController**.

in iOS 10 - when I tap to the row, instead of user's data page, opens the empty UIViewController with white navigation bar

1 个答案:

答案 0 :(得分:0)

这次我通过在addSubView

之前添加延迟来找到解决方案
    double delayInSeconds = 0.1;
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
        [ipadSHSidebarViewController setModalInMain: socialPageNavigationController];
    });