[英]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;
}
但是仍然有兩個探針。
2.UIImageView圖像未更改為Instant_poetry_small.png。
您是否已將drawImage鏈接到xib文件中的UIImageView ?,也許您不會使用Interface Builder鏈接它?
不確定是否會有所幫助,但是請嘗試以下操作:
vw.drawImage = [[UIImageView alloc]initWithImage:tempImage];
代替
[vw.drawImage setImage:tempImage];
其余的代碼對我來說還可以
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.