我有一个名为 TimeLineViewController
的类,它继承自 MyViewController
。我需要将值传递给从 MyViewController
到 TimeLineViewController
的变量。我该怎么做?
MyViewController.h
@interface MyViewController : TimeLineViewController {
.....
}
在 TimeLineViewController.h
中,我分配了一个 String *str
。在 MyViewController.m
中,我需要将一个值传递给 TimeLineViewController
类中的 String *str
变量。我该怎么做。
我尝试了 MyViewController.m
中的以下内容,但没有成功。
[super str]=@"hi";
最佳答案
继承的重点是使用现有功能并根据子类的特定需求扩展它
所以...如果您的 TimeLineViewController
继承自 MyViewController
则无需在 TimeLineViewController
中再次声明该成员,您可以使用它与因为它已经为 MyViewController
声明了:
self.str = @"hi";
关于iphone - 如何将值传递给继承类中的变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19115680/