【发布时间】:2017-08-15 04:11:40
【问题描述】:
在我的基于选项卡的应用程序中,我有一个带有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 nib 在属性检查器中将SpeciesViewController 作为其自定义类。出于这个原因,我希望 ViewDidLoad 或 SpeciesViewController.m 中的任何其他方法在我 pushViewController:speciesController 时被调用。
许多关于加载笔尖问题的帖子都与initWithNibName 与initWithCoder 的错误有关。但是,我相信我正确地使用了initWithNibName,因为我是从视图控制器中这样做的。
感谢您的帮助!非常感谢!
【问题讨论】:
标签: ios objective-c uiviewcontroller nib