-1

在我的 childview 控制器中,我有这个属性:

@property (nonatomic, assign) NSInteger currentItemIndex;

在父视图控制器中,我想设置该值。

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

但在 childViewController 中,currentItemIndex 为 0。

为什么我不能设置?我哪里错了?

4

3 回答 3

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);
}

数据传递视图控制器.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
于 2013-07-10T12:19:12.450 回答
0

尝试在您的 childview 类中读取 _CurrentIndex,此变量应自动生成并使用 setter setItemIndex 方法进行设置。我也有使用 Xcode 的经验,当我为 64 位目标进行构建时,会自动生成带下划线的内部变量,但对于 32 位目标,我必须在接口中声明它并在实现中使用 @synthesize 语句来获取要编译的代码。

于 2013-07-10T11:18:33.483 回答
-1

只需简单地声明,如

@property NSInteger currentItemIndex;

如果它不能解决问题,你必须告诉你在哪里声明属性,哪个类,在接口声明中与否,你正在使用哪个 xcode 等等。发布更多代码。

例如对于 xcode 4.6 这没关系。但是对于旧的 xcode,您已经合成了该属性。

于 2013-07-10T11:10:52.060 回答