简体   繁体   English

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

[英]How to load xib of a viewcontrolller from a custom method?

In my three 20 project i am calling and sending some parameters to a method of my view controller using map object. 在我的三个20项目中,我正在调用并将一些参数发送给使用map对象的视图控制器的方法。 I am passing the image name through parameter to my view controller. 我通过参数将图像名称传递给我的视图控制器。 I have bound a xib file with my view controller . 我已将xib文件与视图控制器绑定。 my xib contains a toolbar at the top and uiimage view. 我的xib在顶部和uiimage视图中包含一个工具栏。 My problem is that when i pass parameter to my custom method and load my xib file in the next line then my view controller's view is not displayed on the screen. 我的问题是,当我将参数传递给自定义方法并在下一行加载xib文件时,视图控制器的视图未显示在屏幕上。 I am receiving the parameter in my custom method but unable to load xib on the screen. 我在自定义方法中接收到参数,但无法在屏幕上加载xib。 I am using the following custom method 我正在使用以下自定义方法

-(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];
}

When i do this i can see my xib loaded on the window. 当我这样做时,我可以看到我的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;
}

But when i do this my xib does not load and i see only a white screen 但是当我这样做时,我的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;
}

This is the issue that i am facing right now. 这是我现在面临的问题。

I solved the above issue by using 我通过使用解决了上述问题

- (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;
}

But still there are two probe. 但是仍然有两个探针。

  1. i am getting extra space between my toolbar at top and uiimageview. 我在顶部的工具栏和uiimageview之间获得了额外的空间。

2.UIImageView image is not changed to instant_poetry_small.png. 2.UIImageView图像未更改为Instant_poetry_small.png。

您是否已将drawImage链接到xib文件中的UIImageView ?,也许您不会使用Interface Builder链接它?

not sure if it will help, but try this: 不确定是否会有所帮助,但是请尝试以下操作:

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

instead of 代替

[vw.drawImage setImage:tempImage];

the rest of the code looks OK for me 其余的代码对我来说还可以

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM