2010-03-02 226 views
0

嘿,我正在玩我的老师提供的基于表格的应用程序的脚本。不过,我似乎无法得到我自己的视图加载。UIViewController not loading UIView

文件:

  • SubViewOneController(这是一个子画面,也有笔尖)
  • TapViewController(自定义的UIView我创建并要添加到单元格)
  • RootViewController的(主控制器,在意见负载)
  • SimpleNavAppDelegate

它是如何工作:在该RootViewController的,T这里是保存它在声明的NSDictionary对象一个NSArray - (无效)awakeFromNib {}方法

- (void)awakeFromNib { 

// we'll keep track of our views controllers in this array 
views = [[NSMutableArray alloc] init];  // when using alloc you are responsible for it, and you will have to release it. 

// ==================================================================================================== 
// ==================================================================================================== 

// LOADING IN CUSTOM VIEW HERE: 

// allocate a set of views and add to our view array as a dictionary item 
TapViewController *tapBoardView = [[TapViewController alloc] init]; 

//push onto array 
[views addObject:[NSDictionary dictionaryWithObjectsAndKeys: 
        @"Tab Gestures",  @"title", 
        tapBoardView,   @"controller", 
        nil]]; 

[tapBoardView release]; //release the memory 

// ==================================================================================================== 
// ==================================================================================================== 

SubViewOneController *subViewOneController = [[SubViewOneController alloc] init]; 

// This will set the 2nd level title 
subViewOneController.title = @"Swipe Gestures"; //set it's title 

//push it onto the array  
[views addObject:[NSDictionary dictionaryWithObjectsAndKeys: 
        @"Swipe Gestures", @"title", 
        subViewOneController, @"controller", 
        nil]]; 

[subViewOneController release]; //release the memory 

}

后来我设置的表格视图:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 

// OUTPUT -- see console 
NSLog(@"indexPath %i", indexPath.row); // OUTPUT: tapController: <TapViewController: 0x3b2b360> 
NSLog(@"view object: %@", [views objectAtIndex:indexPath.row]); // OUTPUT: view object: controller = <TapViewController: 0x3b0e290>; title = "Tab Gestures"; 

// ----- Hardcoding the controller and nib file in does work, so it's not a linkage issue ------ 
// UNCOMMENT TO SEE WORKING -- comment below section. 
//TapViewController *tapContoller = [[TapViewController alloc] initWithNibName:@"TapBoardView" bundle:nil]; 
//NSLog(@"tapController: %@", tapContoller); 
//[self.navigationController pushViewController:tapContoller animated:YES]; 

// ----- Random Tests ----- 
//UIViewController *targetViewController = [[views objectAtIndex: 0] objectForKey:@"controller"];  // DOES NOT WORK 

// LOADS THE SECOND CELL (SubViewOneController) however will not load (TapViewController) 
UIViewController *targetViewController = [[views objectAtIndex: indexPath.row] objectForKey:@"controller"]; 
NSLog(@"target: %@", targetViewController); // OUTPUT: target: <TapViewController: 0x3b0e290> 

[self.navigationController pushViewController:targetViewController animated:YES]; 

}

阅读你应该能够看到硬编码视图的注释,但是试图从View NSArray加载视图不起作用。但它确实包含了内存中的对象,看到NSLog证明了这一点。

所有内容都在TapViewController nib文件中链接和工作。所以,雅,我有点卡在这一个,任何帮助将是伟大的!

谢谢你们

回答

0

您使用在顶部TapViewController错误的初始化方法。视图控制器上的普通旧init不会加载笔尖。假设你的笔尖正确连接(如你所说),如果你没有加载笔尖,那么视图控制器的view属性永远不会被设置为任何东西。所以view财产是零。所以你的视图控制器没有任何视图来显示你的应用程序何时使用它。

TapViewController *tapBoardView = [[TapViewController alloc] init]; 

而你使用正确的你 “硬编码” 一节中:

TapViewController *tapContoller = [[TapViewController alloc] initWithNibName:@"TapBoardView" bundle:nil];