首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ViewController不接受其他ViewController的值

ViewController不接受其他ViewController的值
EN

Stack Overflow用户
提问于 2014-03-21 17:27:48
回答 2查看 168关注 0票数 0

我在做一个旋风球的项目。

当程序启动时,它从视图中的代码中动画到地图的一部分,并加载。

代码语言:javascript
复制
 [globeViewC animateToPosition:MaplyCoordinateMakeWithDegrees(-122.4192, 37.7793) time:1.0];

这很好,但是当我在我的masterView控制器中选择一个单元格时,我也试图让地图有动画,所以我有

代码语言:javascript
复制
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

    if ([[[[TypesArray objectAtIndex:indexPath.row]objectForKey:@"regions"]objectForKey:@"region"]isEqualToString:@"Caribbean"])    
    {

        TestViewController *testView=[[TestViewController alloc]init];

        // Start up over San Francisco

        [testView.globeViewC animateToPosition:MaplyCoordinateMakeWithDegrees(-122.4192, 37.7793) time:1.0];

        NSLog(@"test");
    }

“测试”显示在日志中,但它没有动画到地图上的位置。我将#import "TestViewController.h"添加到该文件的顶部,并且

代码语言:javascript
复制
@property(nonatomic,
strong) WhirlyGlobeViewController *globeViewC;

添加到TestViewController.h中。

代码语言:javascript
复制
#import <UIKit/UIKit.h>
#import "WhirlyGlobeComponent.h"
#import "ConfigViewController.h"

// Map or globe or startup
typedef enum {MaplyGlobe,MaplyGlobeWithElevation,Maply3DMap,Maply2DMap,MaplyNumTypes} MapType;

//The Test View Controller brings up the WhirlyGlobe Component
// and allows the user to test various functionality.

@interface TestViewController : UIViewController <WhirlyGlobeViewControllerDelegate,MaplyViewControllerDelegate,UIPopoverControllerDelegate>
{
    /// This is the base class shared between the MaplyViewController and the WhirlyGlobeViewController
    MaplyBaseViewController *baseViewC;
    /// If we're displaying a globe, this is set
    WhirlyGlobeViewController *globeViewC;
    /// If we're displaying a map, this is set
    MaplyViewController *mapViewC;
    UIPopoverController *popControl;
}

// Fire it up with a particular base layer and map or globe display
- (id)initWithMapType:(MapType)mapType;
@property(nonatomic,strong) NSString *parse;
@property(nonatomic,strong) WhirlyGlobeViewController *globeViewC;
@property(nonatomic,strong) MaplyViewController *mapViewC;
@end
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-03-22 16:21:28

我相信你把事情搞混了..。让我们假设您的主控制器是您的汽车,您的testvc是车轴,您的WhirlyGlobeViewController是车轮。

你现在要做的是:我在我的车里按了一个按钮,它既没有车轴也没有轮子,所以我订购了一个车轴,我希望(不存在的)车轮滚动。这一点都说不通。你必须把你的车轴连接到你的汽车上,然后把轮子接在你的车轴上。

在testviewcontroller中,你的旋转球被附加到视图加载(我猜)中(我猜),但是这个方法从未被调用。您是说testviewcontroller中的行可以工作,这是因为(我猜)您是独立使用testviewcontroller的,并且viewdidload是自动调用的。

从这里你有两个选择。第一个是您的地球仪可用的地方是您的所有程序,然后它可能是MasterViewController的属性或实例变量,而不是TestViewController。然后,您可以将testviewcontroller的视图加载方法中的代码复制到主视图控制器的viewdidload方法中。(旋转地球被初始化的部分)然后你必须调用你的动画

代码语言:javascript
复制
[globeViewC animateToPosition:MaplyCoordinateMakeWithDegrees(-122.4192, 37.7793) time:1.0];
NSLog(@"test");

另一种选择是testviewcontroller应该是独立的,只有全球应该在这里。然后,您可能应该使用pushViewController或添加一个子视图控制器来显示该控制器的某个位置,例如:

代码语言:javascript
复制
TestViewController *testView=[[TestViewController alloc]init];

//If you have a navigation view controller
[self.navigationController pushViewController: testView animated:YES];

//If you don't
[self addChildViewController:testView]; // testView's viewDidLoad will be called here
[self.view addSubview:testView.view];    
NSLog(@"test");
票数 0
EN

Stack Overflow用户

发布于 2014-03-21 17:33:27

尝尝这个

代码语言:javascript
复制
TestViewController *testView=  [[TestViewController alloc] initWithNibName:@"Page1" bundle:nil];

代码语言:javascript
复制
TestViewController *testView = [self.storyboard instantiateViewControllerWithIdentifier:@"viewControllrID"];
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22565545

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档