0

我正在从 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 在交叉中被设置为空。有人能看到我在这里做错了吗?

4

3 回答 3

1

尝试更改您的两个日志语句,如下所示:

NSLog(@"master %@, detail %@", dvc.rowItem, dvc);

NSLog(@" thingy %@ in detail %@", rowItem, self);

我怀疑您创建的细节dvc与视图控制器层次结构中的对象不同。显示对象地址应该验证这是否是答案。

于 2012-07-18T17:34:42.613 回答
0

在“viewWillAppear”中进行设置,我敢打赌它会开始工作。

于 2012-07-18T17:27:42.600 回答
0

请检查这个,

dvc.rowItem = [[NString alloc]initWithString:@"%@",[_objects objectAtIndex:indexPath.row]];
于 2012-07-18T17:34:20.010 回答