2011-05-03 74 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