如何从自定义方法加载viewcontrolller的xib?(How to load xib of a viewcontrolller from a custom method?)

编程入门 行业动态 更新时间:2024-10-18 01:34:47
如何从自定义方法加载viewcontrolller的xib?(How to load xib of a viewcontrolller from a custom method?)

在我的三个20项目中,我正在调用并使用map对象将一些参数发送到我的视图控制器的方法。 我通过参数将图像名称传递给我的视图控制器。 我已经用我的视图控制器绑定了一个xib文件。 我的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。

In my three 20 project i am calling and sending some parameters to a method of my view controller using map object. I am passing the image name through parameter to my view controller. I have bound a xib file with my view controller . my xib contains a toolbar at the top and uiimage view. 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. I am receiving the parameter in my custom method but unable to load xib on the screen. 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.

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

- (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.

i am getting extra space between my toolbar at top and uiimageview.

2.UIImageView image is not changed to instant_poetry_small.png.

最满意答案

不确定它是否会有所帮助,但试试这个:

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

代替

[vw.drawImage setImage:tempImage];

其余的代码对我来说很合适

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

更多推荐

本文发布于:2023-08-07 12:06:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1464484.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自定义   加载   方法   viewcontrolller   method

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!