推送详细信息视图时,字符串设置为null

时间:2012-07-18 17:20:07

标签: iphone ios nsstring null plist

我正在从Master-Detail应用程序模板的主人那里推送一个详细视图。 我想根据单击的行加载具有不同信息的单个视图。我计划从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的{​​{1}}。在DetailViewController的{​​{1}}里面我放了:

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

所以不知何故,rowItem在交叉中被设置为null。 有人能看到我在这里做错了吗?

3 个答案:

答案 0 :(得分:1)

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

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

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

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

答案 1 :(得分:0)

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

答案 2 :(得分:0)

请查看,

dvc.rowItem = [[NString alloc]initWithString:@"%@",[_objects objectAtIndex:indexPath.row]];