1

我非常新的xcode 3,我真的需要幫助這個初始化NSMutableArray

我開發我的應用程序使用UITableView和XML來顯示內容。

我有3個.xib文件,它是rootViewController,SecondViewController和mainview。

所以問題是: 當我嘗試執行didSelectrow在RootViewController的和SecondViewController訪問的NSMutableArray *陣列和替換RootViewController的新數組值*數組值推前動畫。

第一次更改了我的SecondViewController上的數組值,但是當我按下後退按鈕並選擇另一行時,我的SecondViewController數組保持讀取前一個數組不變爲新的數組。我嘗試初始化,但沒有運氣

這是我在RootViewController的UITableView的(didSelectRow)代碼:

​​3210

這是我的第二個視圖控制器:

- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease]; 
    } 

    switch(indexPath.section) 
    { 
     case 0: 

      [cell setText:record.name]; 
      break; 
     case 1: 

      [cell setText:record.Age]; 
      break; 
     case 2: 
     [cell setText:record.summary]; 
      break; 
    } 

    return cell; 
} 

希望有人能幫助我..

在此先感謝.....

+0

因此,ListRecord是NSMutableArray的子​​類?我很困惑,因爲你說你正在設置一個數組,但它看起來像你實際上設置屬性的'記錄'這是類型ListRecord * –

回答

4

幾樣東西,

你這樣做,

2ndController.record = [[[NSMutableArray alloc] init] autorelease]; 

[cell setText:record.name]; 

顯然跟進,在record財產似乎並沒有成爲NSMutableArray實例所以我認爲陣列初始化部分是不正確的,因爲你已經提到了,並且已經提到了,

2ndController.record = record; 

但我認爲的問題是,你保留你的UITableViewController子類。你有沒有嘗試重新加載數據?

[self.tableView reloadData]; 

添加在你DetailViewControllerviewWillAppear方法。

+0

謝謝男人....重新加載數據是我的功能尋求....和初始化..我只是嘗試和錯誤..我知道這是錯的..再次感謝:) – zacual

1

您應該看看再選兩行:

2ndController.record = [[[NSMutableArray alloc] init] autorelease]; 

//inserting the value from firstview to secondview before push 
2ndController.record = record; 

第一行對您沒有任何用處。它創建並初始化一個新的NSMutableArray並將記錄屬性設置爲該新數組。

但是,在接下來的一行中,您將同一個'record'屬性再次設置爲不同的對象,因此第一行中的數組不再被引用。所以你可能不會創造它。

這完全不是你的問題,但這個評論太大而不能評論。 :)