我正在从 Master-Detail Application 模板的 master 推送详细视图。我想根据单击的行加载具有不同信息的单个视图。我计划从 plist 文件加载数据。这是我在 MasterViewController 中使用的代码,当我添加时didSelectRowAtIndexPath:
DetailViewController *dvc = [[DetailViewController alloc]init];
dvc.rowItem = [_objects objectAtIndex:indexPath.row];;
NSLog(@"row is %i", indexPath.row);
NSLog(@"master %@", dvc.rowItem);
其中 rowItem 是NSString
属于DetailViewController
. 在我放viewDidLoad
的里面:DetailViewController
[super viewDidLoad];
NSLog(@" thingy %@", rowItem);
[self setup:rowItem];
setup
看起来像这样:
-(void) setup: (NSString *)eval {
filePath = [NSString stringWithFormat:@"%@.plist",eval];
NSLog(@"%@", filePath);
NSMutableDictionary* plistDict = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
NSString *subName;
NSString *yesNo;
NSString *theseChanges;
subName = [plistDict objectForKey:@"subContractAddress"];
yesNo = [plistDict objectForKey:@"yesOrno"];
theseChanges = [plistDict objectForKey:@"Changes"];
}
这是我的界面:
#import <UIKit/UIKit.h>
@interface DetailViewController : UIViewController
@property (strong, nonatomic) id detailItem;
@property (strong, nonatomic) IBOutlet UILabel *detailDescriptionLabel;
@property (strong, nonatomic) IBOutlet UIButton *finishedButton;
@property (strong, nonatomic) IBOutlet UITextView *changes;
@property (strong, nonatomic) IBOutlet UIButton *saveButton;
@property (strong, nonatomic) IBOutlet UISwitch *test;
@property (strong, nonatomic) IBOutlet UILabel *finishedLabel;
@property (strong, nonatomic) IBOutlet UITextField *subContractName;
@property BOOL needsChanges;
@property (strong, nonatomic) NSString *rowItem;
-(IBAction)change:(id)sender;
-(IBAction)save:(id)sender;
@end
当我构建并运行时,我得到以下控制台输出:
thingy (null)
(null).plist
row is 0
master Excavations
当我按下第一行时,
thingy (null)
(null).plist
row is 1
master Flooring
所以不知何故,rowItem 在交叉中被设置为空。有人能看到我在这里做错了吗?