在我的基於選項卡的應用程序中,我有一個視圖控制器與我在故事板中創建的UITableView
。當你滑動表格中的一個圖像時,我希望當前的視圖控制器(SecondViewController
)加載一個xib文件(SpeciesViewController.xib
),以便「將應用程序」轉換到新視圖。到目前爲止,didSelectRowAtIndexPath
被稱爲滑動,但xib文件從不加載。視圖控制器從其他視圖控制器推不會加載
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
SpeciesViewController* speciesController = [[[SpeciesViewController alloc]initWithNibName:@"SpeciesViewController" bundle:nil] autorelease];
// SpeciesViewController* speciesController = [[SpeciesViewController alloc] init];
Species *theSpecies = [fetchedResultsController objectAtIndexPath:indexPath];
speciesController.theSpecies = theSpecies;
switch (sortBySegmentedControl.selectedSegmentIndex) {
case kSortByCommonNameFirst:
speciesController.title = [theSpecies commonNameFirstLast];
break;
case kSortByCommonNameLast:
speciesController.title = [theSpecies commonNameLastFirst];
break;
case kSortByScientificName:
speciesController.title = [[NSString alloc] initWithFormat:@"%@%@",
[theSpecies.scientificName substringToIndex:1],
[[theSpecies.scientificName substringFromIndex:1] lowercaseString]];
break;
default:
break;
}
speciesController.hidesBottomBarWhenPushed = YES;
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:nil action:nil];
//// Store current index path for viewDidAppear animation. ////
self->currentSelectedIndexPath = indexPath;
[self.navigationController pushViewController:speciesController animated:YES];
}
的SpeciesViewController
筆尖有SpeciesViewController
在屬性檢查器中的自定義類。出於這個原因,我期望在I pushViewController:speciesController
時調用ViewDidLoad或SpeciesViewController.m
的任何其他方法。
很多關於加載筆尖問題的帖子都與initWithNibName
與initWithCoder
的錯誤有關。但是,我相信我正確使用initWithNibName
,因爲我是從視圖控制器中這樣做的。
我感謝任何幫助!非常感謝!
有我的方式來裝載從'SecondViewController'筆尖不需要導航控制器實際? – Matt
@Matt是的,你可以呈現視圖控制器,檢查我的更新的答案,如果面臨問題,請 – 3stud1ant3
presentViewController工作 - 謝謝你! – Matt