0

我正在制作游戏,其中我不使用导航控制器,而是隐藏和取消隐藏不同的控制器现在我的问题如下

这将是查看长描述,您可以理解我在说什么

我的 flowConverViewController 是这样的

#import <UIKit/UIKit.h>
#import "FlowCoverView.h"
#import "NewGameController.h"
#import "MenuController.h"


@class NewGameController;


@interface FlowCoverViewController : UIViewController <FlowCoverViewDelegate>
{

}

@property (nonatomic, strong) NewGameController *game;



- (IBAction)done:(id)sender;



@end

flowcontroller.m 如下所示

当用户单击图像时,图像被选中,游戏应该开始调用该委托方法,如下所示

- (void)flowCover:(FlowCoverView *)view didSelect:(int)image
{
    NSLog(@"Selected Index %d",image);

    UIImage *newimage = [self flowCover:view cover:image];

    [



    NSLog(@"%@",[self.game menu]); // this shows null 
    NSLog(@"%@",self.game); // this shows null thats why my below methods which are in another class is not getting called 

    [self.game menu] playMenuSound];



     // game is object of newGameController that we created in .h file and in 
same way in newgamecontroller there is object properly of menu class and 
playMenuSound is method in menu class





  [self.game imagePickedFromPuzzleLibrary:newimage];
    [self.game startNewGame];


}

唯一的问题是这个方法没有被调用,因为它显示 null 我知道我可以分配初始化它们但我不能这样做以前的数据会丢失我在以前的类中有分配初始化这个属性。

 newgamecontroller.h

    @property (nonatomic, assign) MenuController *menu;

    newgamecontroller.m



      {
      FlowCoverViewController *c = [[FlowCoverViewController alloc] init];

        c.game = self;

        NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"TestFC" owner:self options:nil];
        c = [array objectAtIndex:0];

            [self presentModalViewController:c animated:YES];
        }
4

1 回答 1

1

对不起,你这样做:

FlowCoverViewController *c = [[FlowCoverViewController alloc] init];

c.game = self;

然后你分配给c一个不同的对象:

NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"TestFC" owner:self options:nil];
c = [array objectAtIndex:0];

[self presentModalViewController:c animated:YES];

怎么还能正确设置c属性c.game

编辑:改为尝试

NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"TestFC" owner:self options:nil];
FlowCoverViewController *c = [array objectAtIndex:0];
[self presentViewController:c animated:YES completion:nil]

让我知道。

于 2013-07-05T12:52:49.060 回答