我正在更新我的iPad应用程序,我在分割视图控制器的表格中有一个选项列表,但它没有触发setDetalItem没有触发。由于形状因素(屏幕太小),因此不会移植到iPhone。
来自appDelegate类:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
UINavigationController *navigationController = [splitViewController.viewControllers lastObject];
splitViewController.delegate = (id)navigationController.topViewController;
UINavigationController *masterNavigationController = splitViewController.viewControllers[0];
JSLMasterViewController *controller = (JSLMasterViewController *)masterNavigationController.topViewController;
controller.managedObjectContext = self.managedObjectContext;
return YES;
}
来自masterViewController的:
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
JSLDetailViewController *detailView = self.detailViewController;
detailView.telegram = indexPath.row;
NSLog(@"Did Fire 1");
}
来自我的detailViewController:
- (void)setDetailItem:(id)newDetailItem
{
NSLog(@"Did Fire 2");
if (_detailItem != newDetailItem) {
_detailItem = newDetailItem;
// Update the view.
[self configureView];
}
if (self.masterPopoverController != nil) {
[self.masterPopoverController dismissPopoverAnimated:YES];
}
}
- (void)configureView
{
// Update the user interface for the detail item.
if (self.detailItem) {
//self.detailDescriptionLabel.text = [[self.detailItem valueForKey:@"timeStamp"] description];
NSArray *mainQuestion = [self mainQuestionArray];
NSArray *subQuestion = [self subQuestionArray];
questionTitle.text = mainQuestion[telegram];
subQuestionOne.text = subQuestion[telegram][0];
subQuestionTwo.text = subQuestion[telegram][1];
}
}
我知道我可能需要在appDelegate中创建detailViewController的实例,但我不确定如何执行此操作。我发现的大多数教程都是从头开始构建拆分视图,或者似乎使用旧版本的机制。您可以给我的任何提示将不胜感激!
答案 0 :(得分:0)
您需要设置detailView.detailItem才能触发- (void)setDetailItem:(id)newDetailItem
。
在MasterViewController.m中,detailViewController通常类似于:
self.detailViewController = (DetailViewController *)[[self.splitViewController.viewControllers lastObject] topViewController];
然后在didSelectRowAtIndexPath:
中 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSYourCoolObject *object = _YourObjectArray[indexPath.row];
self.detailViewController.detailItem = object;
}
答案 1 :(得分:0)
事实证明,在iOS6中,需要直接调用“setDetailItem”。你可以在这里传递对象,虽然它不一定是你想的。我将以下代码添加到didSelectItemAtIndexPath:
[detailView setDetailItem:indexPath];
这解决了对MasterViewController的更新,生活很顺利。