0

不要被这个巨大的问题推迟......(它主要是代码)。
好的,我有一个导航控制器,其中包含一个包含 tableView 的视图控制器(称为 AddClaim)。如果选择了一个单元格,则称为:

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(它是一个独占列表)。

在 EditClaimDetails 的 ViewDidLoad 中存在此代码:(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]);
4

2 回答 2

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];

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

在您的单元格中选择方法添加类似

detailViewController.addClaimViewController = self;

(其中 addClaimViewCONtroller 是 EditClaimDetails 对象上的一个属性,例如

@property (nonatomic, retain) Addclaim *addClaimViewController;

然后,您的 pressBack 方法变为

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

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

希望有帮助。

于 2011-05-03T14:56:44.890 回答
0

检查 AddClaim 中的数组属性定义,是否有机会(非原子,副本)?如果是,它将保存您的阵列的私有副本,因此您的原始阵列无法更改。

于 2011-05-03T14:58:21.077 回答