【发布时间】:2012-08-02 23:46:11
【问题描述】:
我正在编写一个具有 3 个视图控制器的简单应用程序。根视图控制器是一个item listing,基本表视图。在这个视图控制器之外,我基于一些用户交互推送了两个不同的视图控制器 - create item 视图控制器或 view item 视图控制器。
所以,情节提要的转场看起来就像一个 V 或其他东西。
在我的create item 视图控制器上,我希望它在用户创建新项目时弹回根视图控制器,然后推送到view item 控制器,以便我可以查看新创建的项目.
我似乎无法让它工作。弹回根视图控制器很容易,但我无法推送 view item 控制器。
有什么想法吗?我在下面粘贴了我的代码。 pop 功能有效,但新视图永远不会出现。
- (void) onSave:(id)sender {
CLLocation *currentLocation = [[LocationHelper sharedInstance] currentLocation];
// format the thread object dictionary
NSArray* location = @[ @(currentLocation.coordinate.latitude), @(currentLocation.coordinate.longitude) ];
NSDictionary* thread = @{ @"title": _titleField.text, @"text": _textField.text, @"author": @"mustached-bear", @"location": location };
// send the new thread to the api server
[[DerpHipsterAPIClient sharedClient] postPath:@"/api/thread"
parameters:thread
success:^(AFHTTPRequestOperation *operation, id responseObject) {
// init thread object
Thread *thread = [[Thread alloc] initWithDictionary:responseObject];
// init view thread controller
ThreadViewController *viewThreadController = [[ThreadViewController alloc] init];
viewThreadController.thread = thread;
[self.navigationController popToRootViewControllerAnimated:NO];
[self.navigationController pushViewController:viewThreadController animated:YES];
}
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
[self.navigationController popToRootViewControllerAnimated:YES];
}];
}
【问题讨论】:
-
我不会为“创建项目”和“查看项目”创建不同的视图控制器。确实,您可能希望在创建项目后查看它,但总有另一种可能性,您的用户可能希望在查看项目后对其进行编辑。设计一个视图控制器来允许在一个视图中创建、查看和编辑会更容易。大多数应用程序都是这样设计的。节省您的时间。
标签: ios xcode cocoa uiviewcontroller uinavigationcontroller