关于类属性的问题显示为null

时间:2013-07-05 12:11:44

标签: iphone ios

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

这将是一个很长的描述,你可以理解我在说什么

我的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我知道我可以分配init他们但我不能这样做以前的数据会丢失我在之前的类中有alloc init这个属性     

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

1 个答案:

答案 0 :(得分: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]

让我知道。