2013-07-10 128 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语句来获取要编译的代码。

相关问题