现在几天我一直在努力使用UISplitViewControllers,这是我的问题:我有一个主视图,声明如下
#import <UIKit/UIKit.h>
#import "DetailViewController.h"
@class DetailViewController;
@interface MasterViewController : UITableViewController {
NSMutableArray *title, *subTitle;
unsigned int quantity;
}
@property (strong, nonatomic) DetailViewController *detailViewController;
@end
在master的.m文件中,一切正常(我可以从sqlite db填充表并在行中显示内容)。当选择一行并填充右侧的详细视图时,没有任何反应。这是行选择:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
MyObject itemFromDB;
/*
... DB stuff here ...
*/
self.detailViewController.detailItem = itemFromDB;
}
现在是DetailViewController实现:
@interface DetailViewController : UIViewController <UISplitViewControllerDelegate>
@property (strong, nonatomic) MyObject *detailItem;
@property (weak, nonatomic) IBOutlet UILabel *name, *phone;
@end
细节是.m:
#import "DetailViewController.h"
@interface DetailViewController ()
- (void)configureView;
@end
@implementation DetailViewController
- (void)setDetailItem:(MyObject *)newItem
{
if (_detailItem != newItem) {
_detailItem = newItem;
[self configureView];
}
}
- (void)configureView
{
if (self.detailItem) {
self.name.text = [self.detailItem name];
self.phone.text = [self.detailItem phone];
}
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self configureView];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
简单来说:在选择行之后,细节没有注意到任何变化。有什么帮助吗?
答案 0 :(得分:3)
你从未定义过self.detailViewController。你应该这样做:
self.detailViewController = self.splitViewController.viewControllers [1];