为什么这段代码使用 presentModalViewController?(不是 pushViewController) [英] why does this code use presentModalViewController? (not pushViewController)

查看:15
本文介绍了为什么这段代码使用 presentModalViewController?(不是 pushViewController)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都明白为什么在 CoreDataBooks 示例代码中:

Anyone understand why in the CoreDataBooks example code that:

(a) 控制器交换差异的方法

虽然单击项目并转到详细视图使用似乎是pushViewController"的标准 UINavigationController 概念,但当您单击添加"新记录按钮时,它会启动通过presentModalViewController"方法添加记录的新视图?也就是说,这两种情况下的方法不能相同,只是使用 pushViewController 方法吗?

Whilst the click an item and go to detailed view uses what seems to be the standard UINavigationController concept of "pushViewController", that when when you click on the "Add" a new record button it launches the new view to add the record via "presentModalViewController" approach? That is, couldn't the approach have been the same in both cases, just using a pushViewController approach?

在使用每种方法的地方使用每种方法实际上有什么好处吗?我看不太清楚.我猜苹果一定有一些东西可以为不同的场景选择这些不同的方法.例如:

Are there actually any advantages to using each approach for where it's been used? I can't quite see. I'd guess there must have been something for Apple to choose these different approaches for different scenarios. For example:

  1. 对用户的任何差异(即UI 差异或功能差异)他们会看到?

  1. any differences to the user (i.e. UI differences or functional differences) that they would see?

开发者的任何差异(或优点/缺点)

any differences for the developer (or advantages/disadvantages)

例如,如果您要考虑在添加"场景中使用 pushViewController 方法而不是 presentModalViewController 方法...

For example, if you were to consider using pushViewController approach instead of the presentModalViewController approach for the for the "Add" scenario...

(b) 数据共享方式差异

他们共享公共数据对象的方法似乎不同 - 所以再次想知道为什么方法不一样?(即在这两种情况下,主控制器都暂时传递给另一个视图,并且它们之间存在一些共享数据 - 即子视图需要传递回父视图)

the approach to how they share the common data object seems to be different - so again just wondering why the approaches weren't the same? (i.e. in both cases the main controller is passing off to another view temporarily and there is some shared data between them - i.e. that the child view needs to pass back to the parent)

代码提取方便

那是编辑":

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    // Create and push a detail view controller.
    DetailViewController *detailViewController = [[DetailViewController alloc] initWithStyle:UITableViewStyleGrouped];
    Book *selectedBook = (Book *)[[self fetchedResultsController] objectAtIndexPath:indexPath];

    // Pass the selected book to the new view controller.
    detailViewController.book = selectedBook;
    [self.navigationController pushViewController:detailViewController animated:YES];
    [detailViewController release];
}

但是对于添加"

- (IBAction)addBook {
    AddViewController *addViewController = [[AddViewController alloc] initWithStyle:UITableViewStyleGrouped];
     addViewController.delegate = self;

     // Create a new managed object context for the new book -- set its persistent store coordinator to the same as that from the fetched results controller's context.
     NSManagedObjectContext *addingContext = [[NSManagedObjectContext alloc] init];
     self.addingManagedObjectContext = addingContext;
     [addingContext release];

     [addingManagedObjectContext setPersistentStoreCoordinator:[[fetchedResultsController managedObjectContext] persistentStoreCoordinator]];
     addViewController.book = (Book *)[NSEntityDescription insertNewObjectForEntityForName:@"Book" inManagedObjectContext:addingContext];
     UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:addViewController];
        [self.navigationController presentModalViewController:navController animated:YES];

     [addViewController release];
     [navController release];

}

谢谢

推荐答案

您使用模态视图控制器将用户的注意力集中在一个任务上.当您推送时,用户处于某种导航流程中,但仍然触手可及整个应用程序.他们可能决定前进或后退,切换到中间的不同选项卡,无论如何.当他们获得模态视图控制器时,他们无法执行任何操作,直到任务完成或取消(模态视图被解除)

You use modal view controllers to focus the user's attention on a Task. When you push, the user is in some kind of navigation flow, but still has the total application at their fingertips. They might decide to go forward or backward, switch to a different tab in the middle, whatever. When they get a modal view controller, they can't do any of that until the task is completed or canceled out of (the modal view is dismissed)

这篇关于为什么这段代码使用 presentModalViewController?(不是 pushViewController)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆