我正在为iPhone写一个简单的纸牌游戏。卡片放在卡片组容器中,卡片组容器是UIScrollView的子类。卡片组放在一个桌面容器中,它是一个UIViewController。在卡片中,我重写了touchesEnded方法,但无法访问包含desk的主类。该怎么做呢?我是不是应该给所有的卡片一个指针才能到达main?或者我能得到父容器吗?
发布于 2012-03-02 06:48:30
您可以在卡片中存储引用。
在卡片界面中,定义如下内容
@interface cards
{
DeskController *deskp;
}
@property (nonatomic, assign) DeskController *deskp;创建卡片时,请指定桌面参考
- (void) setupCards
{
CardController *card = // allocate card
card.deskp = self;
}在卡dealloc()或viewDidUnload中,将其设置为零
self.deskp = nil;https://stackoverflow.com/questions/9515111
复制相似问题