2011-05-03 75 views
0

不要被巨大的问题推迟...(它主要是代码)。
好的,我有一个导航控制器,它包含一个包含tableView的视图控制器(称为AddClaim)。 如果选择的细胞,这就是所谓的:传递的数组未被popViewControllerAnimated传递...为什么?

EditClaimDetails *detailViewController = [[[EditClaimDetails alloc] init] autorelease]; 

// Pass the selected object to the new view controller. 
detailViewController.selectedIndexPath = indexPath; 
detailViewController.newClaimArrayDetails2 = newClaimArrayDetails; 
[self.navigationController pushViewController:detailViewController animated:YES ]; 

这很好地工作,并且示出包含的tableView一个新的视图控制器(它是排他性列表)。

在viewDidLoad中此代码存在EditClaimDetails的:(claimTypeHoldingArray是在头文件中声明的可变数组)

UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStyleBordered target:self action:@selector(pressedBack)]; 

self.navigationItem.leftBarButtonItem = backButton; 

claimTypeHoldingArray = [[NSMutableArray alloc] initWithArray:newClaimArrayDetails2]; 

基本上是如预期的那样的结果如下:返回按钮显示 - 当按下 - 它调用一个将视图控制器弹出到AddClaim的选择器,claimTypeHoldingArray包含AddClaim中给出的newClaimsArray。

这是didSelectRowAtIndexPath方法的代码的一部分:(claimTypeArray是保持细胞的textLabels阵列)

[claimTypeHoldingArray replaceObjectAtIndex:0 withObject:[claimTypeArray objectAtIndex:indexPath.row]]; 

这里做的事情是,claimTypeHoldingArray的第一对象被替换什么文本是在单元格的TextLabel。到现在为止还挺好。 (带的NSLog测试)

这是当按下后退按钮的代码:

-(IBAction)pressedBack { 

AddClaim *sender = [[[AddClaim alloc] init] autorelease]; 

sender.newClaimArrayDetails = claimTypeHoldingArray; 

[self.navigationController popViewControllerAnimated:YES]; 

这就是麻烦开始的地方...... 这个动作(据我)应该claimTypeHoldingArray取代newClaimArrayDetails 。 (它这样做)当视图控制器被弹出,屏幕移回添加声明时,这个数组没有改变! 我做了什么错了?顺便说一句,所有的属性都设置。 这是测试我在viewDidAppear做:

NSLog(@"%@",[newClaimArrayDetails objectAtIndex:0]); 

回答

1

这个答案是同等规模的问题,希望它不要过大;)

所以,你想你的pressedBack按钮方法使用claimTypeHoldingArray更新初始AddClaim视图控制器对象。

你是半途而废 - 你肯定是更新一个AddClaim对象,而不是你的导航控制器里面的那个。您正在创建一个新的并更新它!

-(IBAction)pressedBack { 
    // This line creates a new AddClaim view controller 
    AddClaim *sender = [[[AddClaim alloc] init] autorelease]; 

    // This line updates your _new_ AddClaim view controller 
    sender.newClaimArrayDetails = claimTypeHoldingArray; 

    // This line displays the _old_ AddClaim object 
    [self.navigationController popViewControllerAnimated:YES]; 

你需要传递到您的EditClaimDetails视图控制器创建它的AddClaim视图控制器。

在您的小区选择的方法添加类似

detailViewController.addClaimViewController = self; 

(其中addClaimViewCOntroller是您EditClaimDetails对象的属性,像

@property (nonatomic, retain) Addclaim *addClaimViewController; 

然后,你pressedBack方法变得

-(IBAction)pressedBack { 
    // This line updates your _old_ AddClaim view controller 
    addClaimViewController.newClaimArrayDetails = claimTypeHoldingArray; 

    // This line displays the _old_ AddClaim object 
    [self.navigationController popViewControllerAnimated:YES]; 

希望有所帮助。

+0

这似乎很合乎逻辑,应该工作,但我得到这个错误,我放置propery声明。 'Addclaim'_ – SEG 2011-05-03 15:27:39

+0

AddClaim之前的资本C中的_expected specifier-qualifier-list? – deanWombourne 2011-05-03 15:32:11

+0

或者您需要#import“AddClaim.h”在顶部附近的某处。那个错误意味着它不知道AddClaim是什么:) – deanWombourne 2011-05-03 15:32:45

0

在AddClaim中检查数组属性的定义,是否有机会(非原子,复制)?如果是的话,它会持有你的数组的私人副本,所以你原来的数组不能改变。

+0

没有它:(非原子,保留)... – SEG 2011-05-03 15:14:42

+0

我想deanWombourne是对的,我只是在想... ... – 2011-05-03 16:09:47