Ios 在UISplitViewController中将int从MasterView传递到DetailView
我有一个UISplitViewController,在其中我试图将一个int值从MasterViewController传递给DetailTableViewController。主视图控制器和局部视图控制器都是UITableViewController。我正在尝试将indexPath.row值从主节点传递给detail,这将指示将哪个对象数组加载到detailViewController的tableview中 来自MasterViewController.m的一些代码Ios 在UISplitViewController中将int从MasterView传递到DetailView,ios,ipad,uisplitviewcontroller,Ios,Ipad,Uisplitviewcontroller,我有一个UISplitViewController,在其中我试图将一个int值从MasterViewController传递给DetailTableViewController。主视图控制器和局部视图控制器都是UITableViewController。我正在尝试将indexPath.row值从主节点传递给detail,这将指示将哪个对象数组加载到detailViewController的tableview中 来自MasterViewController.m的一些代码 - (void)table
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
int indexRowTouched = indexPath.row;
detailViewController = [self.splitViewController.viewControllers lastObject];
NSLog(@"%@", detailViewController);
detailViewController.detailItem = indexRowTouched;
NSLog(@"index row %i", indexRowTouched);
}
- (void)setDetailItem:(int)newDetailItem
{
if (_detailItem != newDetailItem) {
_detailItem = newDetailItem;
// Update the view.
[self configureView];
}
if (self.masterPopoverController != nil) {
[self.masterPopoverController dismissPopoverAnimated:YES];
}
}
这里抛出一个异常
detailViewController.detailItem = indexRowTouched;
2012-03-28 16:08:19.625 splittest2[14895:f803]-[UINavigationController setDetailItem:]:发送到实例0x6b592e0的选择器无法识别
从DetailViewController.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
int indexRowTouched = indexPath.row;
detailViewController = [self.splitViewController.viewControllers lastObject];
NSLog(@"%@", detailViewController);
detailViewController.detailItem = indexRowTouched;
NSLog(@"index row %i", indexRowTouched);
}
- (void)setDetailItem:(int)newDetailItem
{
if (_detailItem != newDetailItem) {
_detailItem = newDetailItem;
// Update the view.
[self configureView];
}
if (self.masterPopoverController != nil) {
[self.masterPopoverController dismissPopoverAnimated:YES];
}
}
我还注意到,只要加载了detailView,detailItem的值就会记录为0,然后就选择了indexPath行
我想知道为什么没有从MasterViewController分配此属性,并且没有更新TableView
编辑
尝试访问UINavigationController上的setDetailItem似乎已被修复,方法是在-voidconfigureView函数中将didSelectRowAtIndexPath更改为上述路径
if (self.detailItem) {
if (detailItem == 0) {
NSString *medPath = [[NSBundle mainBundle] pathForResource:@"general" ofType:@"plist"];
NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithContentsOfFile:medPath];
self.items = dict;
NSMutableArray *array = [[NSMutableArray alloc] init];
[array addObjectsFromArray:[[self.items allKeys]
sortedArrayUsingSelector:@selector(compare:)]];
self.keys = array;
}
//etc
}
因为detailItem是一个int,而不是一个对象,如果它等于0,if detailItem将返回false。因此,如果将0发送到detailItem,则不会输入configureView if语句,并且不会发生任何事情
您应该完全删除该外部if语句,并且只需:
- (void)configureView {
if (detailItem == 0) {
NSString *medPath = [[NSBundle mainBundle] pathForResource:@"general" ofType:@"plist"];
NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithContentsOfFile:medPath];
self.items = dict;
NSMutableArray *array = [[NSMutableArray alloc] init];
[array addObjectsFromArray:[[self.items allKeys]
sortedArrayUsingSelector:@selector(compare:)]];
self.keys = array;
}
//other cases for detailItem
}
谢谢你看。我改变了尝试访问detailViewController的方式,请参见上面的编辑,这似乎有所帮助,但是detailView对象在detailViewController端仍然记录为null。如果能够查看所有代码,这将非常有帮助。你能发布一个链接到DetailViewController的整个.h和.m吗?一个图像也可以。、、MasterViewController.h/m和DetailViewController.h/mYep。。。就是这样。我有一种感觉,这和。。。谢谢你花时间帮忙!我删除了第一条if语句,然后将[self.tableview reloadData]添加到每个案例中,它的性能非常好。再次感谢!