#objective-c #ios10 #didselectrowatindexpath #addsubview
#objective-c #ios10 #didselectrowatindexpath #addsubview
Вопрос:
У меня проблема:
Главная страница моего iPad разделена на два представления.
1-е меню (UITableView) (левая сторона);
2-я рабочая область (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 — это страница пользователя, и это первое, что мы видим в рабочей области при запуске приложения.
SocialPageViewController получил UIViewTable со списком друзей. Когда пользователь нажимает на строку в списке друзей, инициализируйте новый UIViewControler с данными выбранного пользователя, используя метод setModalInMain UIViewController рабочей области (iPadSHSidebarViewController).
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?
Ответ №1:
На этот раз я нахожу решение, добавляя задержку перед добавлением SUBVIEW
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];
});