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文件中鏈接和工作。所以,雅,我有點卡在這一個,任何幫助將是偉大的!
謝謝你們