我正在使用 XCode 4.5 和 ARC 创建 iPad 版本的主从应用程序。我设置了 iPadMaster.h/.m(作为我的主控)和 iPadDetailViewController.h/m(作为我的详细信息)。
当用户单击/选择 iPadMaster 上的行时,我尝试从 iPadDetailViewController 加载不同的 View Controller 。
在 iPadDetailController.h 上,我设置了这个:
@property int itemNumber;
在 iPadMaster.h 上,我将其称为:
@class iPadDetailViewController;
并继续这样做:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
DetailViewController * DVC = [[DetailViewController alloc]init];
DVC.itemNumber = indexPath.row;
}
在 iPadDetailViewController 上,我设置了这个:
- (void)configureView
{
switch (_itemNumber) {
case 1:
{
iPadLogin *next = [[iPadLogin alloc] init];
NSMutableArray *mut = [[NSMutableArray alloc]init];
mut = [self.splitViewController.viewControllers mutableCopy];
[mut replaceObjectAtIndex:1 withObject:next];
self.splitViewController.viewControllers = mut;
break;
}
default:{
self.view.backgroundColor = [UIColor whiteColor];
}
break;
}
}
//then i called it on:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self configureView];
}
当我单击主表中的第二行时,item_number 应该为 1 并加载“iPadLogin”,但没有任何反应...非常感谢任何指针...
提前致谢...
最佳答案
正如我在评论中所说,我认为您应该从主 Controller 更改详细 Controller 。您在主 Controller 中决定要转到哪个详细 Controller (通过在表中选择一行),因此主 Controller 应该负责进行更改。下面的代码应该做到这一点(但是请注意,如果您为 Controller 使用 Storyboard,那么您应该使用 [self.storyboard instantiateViewControllerWithIdentifier:@"whatever"] 来获取下一个 Controller 而不是 alloc init)。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
switch (indexPath.row) {
case 1:
{
iPadLogin *next = [[iPadLogin alloc] init];
NSMutableArray *mut = [[NSMutableArray alloc]init];
mut = [self.splitViewController.viewControllers mutableCopy];
[mut replaceObjectAtIndex:1 withObject:next];
self.splitViewController.viewControllers = mut;
break;
}
case 2:
{
AnotherVC *another = [[AnotherVC alloc] init];
NSMutableArray *mut = [[NSMutableArray alloc]init];
mut = [self.splitViewController.viewControllers mutableCopy];
[mut replaceObjectAtIndex:1 withObject:another];
self.splitViewController.viewControllers = mut;
break;
}
default:{
UIViewController *detail = self.splitViewController.viewControllers[1];
detail.view.backgroundColor = [UIColor whiteColor];
}
break;
}
}
关于ios - 主详细信息应用程序未加载 UIViewControllers,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15723174/