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

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

问题描述

任何人都能理解为什么在CoreDataBooks示例代码中:

Anyone understand why in the CoreDataBooks example code that:

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

(a) method for controller swapping difference

虽然单击一个项目并转到详细视图,但使用的似乎是 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)数据共享方法差异

(b) data sharing approach difference

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

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)

便利的代码提取

Code Extract for Convenience

这是编辑:

- (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天全站免登陆