导航视图控制器问题

发布于 2024-07-22 20:39:29 字数 600 浏览 4 评论 0原文

以下是我想要实现的内容:

  1. 我的应用程序的主屏幕是 UITableView。 表视图中的每一行都是一个类别,当您单击该行中的详细信息公开按钮时,您可以在类别详细视图中看到该类别下的一堆项目。

  2. 现在在主屏幕中,我单击导航栏中的“+”按钮来创建一个新类别。 (新类别将成为表视图中的新行)。 然后应用程序将我带到“添加类别”视图。 (我使用了presentModalViewController)

  3. 在“添加类别”视图中,我设置了一些内容,然后单击“保存”按钮以关闭“添加类别”视图。 (我使用了missModalViewControllerAnimated)

  4. 通常在我单击“保存”按钮后,应用程序会将我带回主视图,我会在表格中看到一个新行。

  5. 但这不是我想要的,我想要的是 - 单击“保存”按钮后,“添加类别”视图将被关闭,但不会返回到主视图。 相反,我将看到新创建的类别的详细信息,以便我可以继续在此类别下添加项目。 结果就像“我返回主视图,然后单击新创建的行(类别)的详细信息公开按钮”。

  6. 有人知道如何实现这一点吗? 谢谢!

Below is what I want to implement:

  1. The main screen of my app is a UITableView. Each row in the table view is a category, when you click the detail disclosure button in the row, you can see a bunch of items under this category in the category detail view.

  2. Now in the main screen, I click the "+" button in navigation bar to create a new category. (The new category will become a new row in the table view). The app then take me to the "Add Category" view. (I used presentModalViewController)

  3. In the "Add Category" view, I set something, then click "Save" button to dismiss the "Add Category" view. (I used dismissModalViewControllerAnimated)

  4. Usually after I click "Save" button, the app will take me back to the main view and I will see a new row in the table.

  5. But that's not what I want to go, what I want is - after I click the "save" button, the "Add category" view will be dismissed but not return to the main view. Instead, I will see the details of the new-created category so I can continue to add items under this category. The result is just like "I return to the main view and then click the detail disclosure button of the new-created row (category)".

  6. Does any one know how to realize that? Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一抹微笑 2024-07-29 20:39:29

如果您使用 presentModalViewController 及其相应的 dismissModalViewControllerAnimated,那么您将返回到发出初始 presentModalViewController 消息的视图控制器。

相反,您可能希望将负责添加新类别的视图控制器推入堆栈,完成后,您只需将负责显示该类别的所有项目的视图控制器推入堆栈即可。 因此,您应该使用

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated

If you use presentModalViewController and its corresponding dismissModalViewControllerAnimated, then you will return to the view controller in which you issued the initial presentModalViewController message.

Instead, you may want to push on the stack the view controller in charge of adding the new category, and when you are done, you simply push on the stack the view controller responsible for showing all of the items of that category. Thus, you should use

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
灯角 2024-07-29 20:39:29

您可以通过将一个屏幕与另一个屏幕进行一些解耦来做到这一点:

- 为您的类别创建模式对话框创建自定义委托和协议。 简单的事情如下:

@protocol CategoryCreationProtocol
- (void) categoryAddDone:(NSString *)category;
- (void) categoryAddCancelled;
@end
...

@interface CategoryCreationDialog : UIViewController {
...
    id<NSObject, CategoryCreationProtocol> categoryDelegate;
}

@property (assign) id< CategoryCreationProtocol, NSObject> categoryDelegate;

- 在模式对话框中,当用户点击“保存”按钮时,在关闭视图控制器后,您调用委托方法:

if (categoryDelegate && [categoryDelegate 
        respondsToSelector:@selector(categoryAddDone:)])
            [categoryDelegate categoryAddDone:newCategory];

此外,还有类似于“取消”按钮的方法。

- 您的主控制器实现categoryAddDone 方法并将其自身设置为模式对话框的categoryDe​​legate

- 在运行时,当用户点击Save时,将调用委托方法,以便您的主视图收到发生了某些事情的通知,并且它可以将正确的视图推入到位,甚至跳转到正确的类别。

- 在您的情况下,一旦类别创建完成,主视图控制器就会收到通知,因此它可以释放类别创建对话框并将类别详细信息视图推入堆栈。 用户看到模式对话框消失并直接滑入详细视图。

- 一般来说,使用委托/协议进行推送导航控制器和模式对话框是制作解耦和可重用视图的一种非常方便的模式。 这样就可以从不同的地方调用它们。 为了保持一致,您可能还希望在每个模式对话框上都有一个 show 方法,并推送调用者可以调用的视图控制器。 这样,就可以以一致的方式进入,并以一致的方式通知用户已完成操作。

You can do this by doing a little decoupling of one screen from another:

- Create a custom delegate and protocol for your category creation modal dialog. Something simple like:

@protocol CategoryCreationProtocol
- (void) categoryAddDone:(NSString *)category;
- (void) categoryAddCancelled;
@end
...

@interface CategoryCreationDialog : UIViewController {
...
    id<NSObject, CategoryCreationProtocol> categoryDelegate;
}

@property (assign) id< CategoryCreationProtocol, NSObject> categoryDelegate;

- In the modal dialog when the user taps the 'Save' button, after dismissing the view controller, you invoke the delegate method:

if (categoryDelegate && [categoryDelegate 
        respondsToSelector:@selector(categoryAddDone:)])
            [categoryDelegate categoryAddDone:newCategory];

Also, something similar for the Cancel button.

- Your main controller implements the categoryAddDone method and sets itself to be the categoryDelegate for the modal dialog.

- At runtime, when the user taps Save the delegate method is invoked so your main view is notified that something has happened and it can push the right view into place and even jump to the proper category.

- In your case, as soon as the category creation is done, the main view controller is notified, so it can release the category creation dialog and push the category detail view into the stack. The user sees the modal dialog disappear and slides right into the detail view.

- In general, using delegate/protocols for push navcontroller and modal dialogs is a really handy pattern for making decoupled and reusable views. This way they can be invoked from a variety of places. To make it consistent, you may also want to have a show method on each modal dialogs and pushed view controllers that the caller can invoke. This way there's a consistent way to get into and a consistent way to get notified that the user is done with it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文