2013-07-10 127 views
-1

在我childview控制器我有這樣的特性:爲什麼NSInteger無法從父視圖控制器中設置?

@property (nonatomic, assign) NSInteger currentItemIndex; 

在父視圖控制器,我想設置這個值。

[childViewController setCurrentItemIndex:5]; 
    [self.navigationController pushViewController:childViewController animated:YES]; 

但在childViewController,currentItemIndex爲0

爲什麼我不能設置呢?我錯在哪裏?

+0

你合成過嗎?你把它放在其他地方嗎? –

+0

訪問它時發佈您的代碼 – Vinodh

回答

1

ReceiverViewController.h

@property (nonatomic, assign) NSInteger currrentIndex; 

ReceiverViewController.m

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 
    NSLog(@"Index value %d",self.currrentIndex); 
} 

DataPassingViewController.m

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    // Navigation logic may go here. Create and push another view controller. 


    DataPassingViewController *detailViewController = [[DataPassingViewController alloc] initWithNibName:@"DataPassingViewController" bundle:nil]; 
    detailViewController.currrentIndex = 5; 
    // Pass the selected object to the new view controller. 
    [self.navigationController pushViewController:detailViewController animated:YES]; 
} 

我使用上述代碼其給出輸出如下:

2013-07-10 17:50:10.230 DataPassing[3881:c07] Index value 5 
-1

只是簡單地聲明,作爲

而如果不解決這個問題,你一定要告訴你哪裏財產申報,其類,在接口聲明與否,它的Xcode您正在使用等。發佈更多代碼。

例如對於xcode 4.6這沒關係。但對於舊的xcode,你已經綜合了這個屬性。

+1

爲什麼NSInteger不能是非原子的並且分配? – Exploring

+1

當你聲明一個屬性時,你也提到了你也使用了「assign」和「atomic」,因爲它們是默認行爲。 – Exploring

0

嘗試讀取您的childview類中的_CurrentIndex,應該使用setter setItemIndex方法自動生成並設置此變量。 我也有Xcode的經驗,當我爲64位目標構建時,帶有下劃線的內部變量是自動生成的,但對於32位目標,我必須在接口中聲明它,並在實現中使用@synthesize語句來獲取要編譯的代碼。

相關問題