Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何从自定义方法加载ViewController的xib?_Iphone_Objective C_Ios - Fatal编程技术网

Iphone 如何从自定义方法加载ViewController的xib?

Iphone 如何从自定义方法加载ViewController的xib?,iphone,objective-c,ios,Iphone,Objective C,Ios,在我的three 20项目中,我使用map对象调用并向视图控制器的方法发送一些参数。我正在通过参数将图像名称传递给我的视图控制器。我已经用视图控制器绑定了一个xib文件。my xib在顶部和uiimage视图中包含一个工具栏。我的问题是,当我将参数传递给我的自定义方法并在下一行加载我的xib文件时,我的视图控制器的视图不会显示在屏幕上。我在自定义方法中收到参数,但无法在屏幕上加载xib。 我使用以下自定义方法 -(void)loadImageWithName:(NSString *)img {

在我的three 20项目中,我使用map对象调用并向视图控制器的方法发送一些参数。我正在通过参数将图像名称传递给我的视图控制器。我已经用视图控制器绑定了一个xib文件。my xib在顶部和uiimage视图中包含一个工具栏。我的问题是,当我将参数传递给我的自定义方法并在下一行加载我的xib文件时,我的视图控制器的视图不会显示在屏幕上。我在自定义方法中收到参数,但无法在屏幕上加载xib。 我使用以下自定义方法

-(void)loadImageWithName:(NSString *)img
{
    PhotoView *vw = [[PhotoView alloc] initWithNibName:@"PhotoView" bundle:nil];
    UIImage *tempImage = [UIImage imageNamed:img];
    [vw.drawImage setImage:tempImage]; 
    [self presentModalViewController:vw animated:YES];
}
当我这样做时,我可以看到我的xib加载在窗口上

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [[TTURLRequestQueue mainQueue] setMaxContentLength:0];

     TTNavigator *navigator = [TTNavigator navigator];
    navigator.window = _window;

    TTURLMap *map = navigator.URLMap;
    [map from:@"tt://appPhotos" toSharedViewController:[PhotoViewController class]];
    [map from:@"tt://photo" toSharedViewController:[PhotoView class]];
    [navigator openURLAction:[TTURLAction actionWithURLPath:@"tt://photo"]];

    [_window makeKeyAndVisible];

    return YES;
}
但当我这样做时,我的xib不会加载,我只看到一个白色屏幕

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [[TTURLRequestQueue mainQueue] setMaxContentLength:0];

    TTNavigator *navigator = [TTNavigator navigator];
    navigator.window = _window;

    TTURLMap *map = navigator.URLMap;
    [map from:@"tt://appPhotos" toSharedViewController:[PhotoViewController class]];
    [map from:@"tt://photo/(loadImageWithName:)" toSharedViewController:[PhotoView class]];
    [navigator openURLAction:[TTURLAction actionWithURLPath:@"tt://photo/myphoto.png"]];

    [_window makeKeyAndVisible];

    return YES;
}
这是我现在面临的问题

我通过使用解决了上述问题

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [[TTURLRequestQueue mainQueue] setMaxContentLength:0];

     TTNavigator *navigator = [TTNavigator navigator];
    navigator.window = _window;

    TTURLMap *map = navigator.URLMap;
    [map from:@"tt://appPhotos" toSharedViewController:[PhotoViewController class]];
    [map from:@"tt://photo/detail?name=(initWithImage:)" toSharedViewController:[PhotoView class]];
    [navigator openURLAction:[TTURLAction actionWithURLPath:[NSString stringWithFormat:@"tt://photo/detail?name=%@",@"level_me_up_small.png"]]];

    [_window makeKeyAndVisible];

    return YES;
}

但仍然有两个问题

  • 我在顶部的工具栏和uiimageview之间获得了额外的空间
    2.UIImageView图像未更改为instant_poetry_small.png。

    您是否已将drawImage链接到xib文件中的UIImageView?可能您不会使用Interface Builder将其链接

    不确定是否有帮助,但请尝试以下操作:

    vw.drawImage = [[UIImageView alloc]initWithImage:tempImage];
    
    而不是

    [vw.drawImage setImage:tempImage];
    

    代码的其余部分对我来说似乎还可以

    我已经将UIImageView与drawImage链接了。-(BOOL)应用程序:(UIApplication*)应用程序完成了使用选项的启动:(NSDictionary*)启动选项{[[TTURLRequestQueue mainQueue]setMaxContentLength:0];TTNavigator*navigator=[TTNavigator];navigator.window=_window;TTURLMap*map=navigator.URLMap;[map from:@“tt://appPhotos”toSharedViewController:[PhotoViewController类]];[map from:@“tt://photo”toSharedViewController:[PhotoView类]];[navigator openURLAction:[TTURLAction action action withurlpath:@“tt://photo”]];[u window makeyeandvisible];返回YES;}而不是将[map from:@“tt://photo/(loadImageWithName:)”映射到SharedViewController:[PhotoView类]];尝试将[map from:@“tt://photo/(loadImageWithName:)”映射到ViewController:[PhotoView类]];现在我正在使用[map from:@“tt://photo/detail?name=(initWithImage:)”来访问SharedViewController:[PhotoView类];它工作得很好。我还评论了两个问题。你能帮我解决这个问题吗?假设我有一个xib,它有一个UIImageView和一个工具栏。我正在从initWithNibName加载我的xib文件,在下一行我已经编写了更改UIImageView图像的代码。有什么问题吗?我想更改UIImageView的图像,但它显示了我在interface builder上随UIImageView附加的图像。我的loadImageWithName方法位于我的PhotoView类中,我确信它正在运行,但无法加载xib。原因可能是什么?你能告诉我吗?假设我有一个xib,它有一个UIImageView和一个工具栏。我正在从initWithNibName加载我的xib文件,在下一行我已经编写了更改UIImageView图像的代码。有什么问题吗?我想更改UIImageView的图像,但它显示的是我在interface builder上随UIImageView附带的图像。现在我使用以下方法加载了我的xib—(id)initWithImage:(NSString*)img{//NSLog(@“%@),NSStringFromClass([img class]);PhotoView*vw=[[PhotoView alloc]initWithNibName:@“PhotoView”bundle:nil];UIImage*tempImage=[UIImage ImageName:@“instant_poetry_small.png”];[vw.drawImage setImage:tempImage];[self-presentModalViewController:vw-animated:YES];返回self;}但仍然有两个探测器。1.我在顶部的工具栏和uiimageview之间获得了额外的空间。2.UIImageView图像未更改为instant_poetry_small.png。NIB文件是否至少已加载?您可以登录vw查看它是否是有效的参考资料吗?如果您尝试的内容都不起作用,则可能是文件名有问题,或者NIB文件未包含在应用程序捆绑包中。我的NIB文件正在加载。但在运行时工具栏和uiimageview之间有一些空白。这对我来说是有效的-(void)viewDidLoad{[super viewDidLoad];UIImage*tempImage=[UIImage ImageName:@“instant_poetry_small.png”];drawImage.image=tempImage;}-(id)initWithImage:(NSString*)img{[super viewDidLoad];返回self;}