下のプロパティを初期化したり、使用して取得することはできません:は私が<em>非常に</em>シンプルNSObjectの作ったカスタムNSObjectのはiOSの5
GameSetUpData.h
@interface GameSetUpData : NSObject
@property (readwrite, nonatomic) NSUInteger numberOfPlayers;
@property (strong, nonatomic) NSMutableArray *playerNames;
@property (strong, nonatomic) NSString *gameType;
@property (readwrite, nonatomic) NSUInteger numberOfMinutes;
@property (readwrite, nonatomic) NSUInteger numberOfTurns;
@property (readwrite, nonatomic) CGSize boardSize;
@end
をGameSetUpData.m
#import "GameSetUpData.h"
@implementation GameSetUpData
@synthesize numberOfPlayers = _numberOfPlayers;
@synthesize playerNames = _playerNames;
@synthesize gameType = _gameType;
@synthesize numberOfMinutes = _numberOfMinutes;
@synthesize numberOfTurns = _numberOfTurns;
@synthesize boardSize = _boardSize;
@end
このクラスは、基本的にデータを保持しています。私はその後、私のViewControllerをして、このオブジェクトを使用しよう:
MainMenu.h
#import <UIKit/UIKit.h>
@class GameSetUpData;
@interface MainMenu : UIViewController
@property (strong, nonatomic) GameSetUpData *gameSetUp;
-(IBAction)tappedNewGame:(id)sender;
-(IBAction)tappedTwoPlayers:(id)sender;
...
MainMenu.m
#import "MainMenu.h"
#import "MJViewController.h"
#import "GameSetUpData.h"
@implementation MainMenu
@synthesize gameSetUp = _gameSetUp;
...
-(IBAction)tappedTwoPlayers:(id)sender {
_gameSetUp.numberOfPlayers = 2;
NSLog(@"number of Players: %d", _gameSetUp.numberOfPlayers);
}
残念ながら、私のNSLogはnumberOfPlayersが0に等しいことを言います私のGameSetUpDataで何が間違っていますか?私は、iOS5ではalloc/initを呼び出す必要はなく、deallocメソッドを作る必要はないと言われました。 GameSetUpDataにはまだ-(void)init
メソッドが必要ですか?あなたのすべての時間をありがとう!
編集:オブジェクトを割り当て/初期化してください - ARC ONLYはrelease/retain/autoreleaseを扱います。あなたはまだオブジェクトのインスタンスを作る必要があります!私は誤った情報についてお詫び申し上げます。私はRTFMに次回を確実にするでしょう...
これまで嘘つきだと言った人は誰ですか?あなたはallocとinitを持っていなければなりません。ARCを使ってautoreleaseを保持したり解放したりする必要はありません。 – ColdLogic
私はColdLogicに謝罪します。誤情報を広げようとはしませんでした。もう私はおそらく、ここで質問をする前にこれを試してみるべきです、私はちょうどiOS5がiOS4とどのように違うかに驚いています。ありがとうございました。 – Max