改变财产价值

时间:2013-02-27 17:00:10

标签: ios cocoa-touch uiviewcontroller uikit

我有两个视图控制器,aViewController和bViewController,bViewController是aViewController的子类。我在aViewController中声明了一些属性,在bViewController中我可以读取该属性的值但是如果我尝试更改它们的值,则值不会改变并且在更改之前保持第一个。

1 个答案:

答案 0 :(得分:0)

请确保您拥有以下内容:

// "A" view controller
@interface AViewController : UIViewController

@property (nonatomic, strong) NSString *name;

@end


// "B" view controller
@interface BViewController : AViewController

- (void)changePropertyValue;

@end

@implementation BViewController

- (void)changePropertyValue
{
    self.name = @"Bill";
    NSLog(self.name);
    self.name = @"Steve";
    NSLog(self.name);
}

@end

// create your BViewController
BViewController *theController = [[BViewController alloc] init];
[theController changePropertyValue];