再び私です。私は過去 1 時間半、これに苦労してきましたが、これを実装する良い方法を見つけることができないようです。私は基本的に、ボタンをクリックするとラベルに結果を表示しようとしています。(xcodeを使い始めたばかりなので、そのアクションに適切な用語かどうかはわかりません)。とにかく、これが私のコードとコントローラーのメソッドです。
@interface Match : NSObject{
}
@property NSInteger *Id;
@property NSString *fighter1, *fighter2;
- (id) initWithWCFId:(NSInteger)matchId bracketId:(NSInteger)bracketId;
@end
@implementation Match
- (id) initWithWCFId:(NSInteger)matchId bracketId:(NSInteger)bracketId{
self = [self init];
if(self){
self.Id = &(matchId);
self.fighter1 = @"Person 1";
self.fighter2 = @"Person 2";
}
return self;
}
@end
--- コントローラ ---
@interface ViewController : UIViewController{
/*IBOutlet UITextField *txtFieldBracketId;
IBOutlet UITextField *txtFieldMatchId;*/
}
@property (weak, nonatomic) IBOutlet UITextField *txtFieldBracketId;
@property (weak, nonatomic) IBOutlet UITextField *txtFieldMatchId;
- (IBAction)btnSubmit:(id)sender;
@end
- - 実装
- (IBAction)btnSubmit:(id)sender {
@autoreleasepool {
Match *match = [[Match alloc]initWithWCFId:[_txtFieldMatchId.text integerValue] bracketId:[_txtFieldBracketId.text integerValue]];
self.lblMatchId.text = [[NSString alloc] initWithString:[NSNumber numberWithInt:match.Id]];
self.lblFighter1.text = [[NSString alloc] initWithString:match.fighter1];
self.lblFighter2.text = [[NSString alloc] initWithString:match.fighter2];
}
}
私は基本的に2つのテキストボックスを持っています。ボタンをクリックすると、これらのテキスト ボックスの値が取得され、それらの入力に基づいて取得したデータが表示されます。次に、次の 3 つのデータが表示されます。
ID、Fighter1、Fighter2。
ボタンをクリックすると、すべてが停止し、次のエラーが表示されます。
NSInvalidArgumentException', reason: '-[__NSCFNumber length]: unrecognized selector sent to instance 0x74656e0' * First throw call stack: (0x1c90012 0x10cde7e 0x1d1b4bd 0x1c7fbbc 0x1c7f94e 0xae4841 0x2891 0x10e1705 0x18920 0x188b8 0xd9671 0xd9bcf 0xd8d38 0x4833f 0x48552 0x263aa 0x17cf8 0x1bebdf9 0x1bebad0 0x1c05bf5 0x1c05962 0x1c36bb6 0x1c35f44 0x1c35e1b 0x1bea7e3 0x1bea668 0x1565c 0x23dd 0x2305) libc++abi.dylib: 例外をスローして呼び出された終了
1かどうかはわかりません。プロパティIDに「NSInteger」を使用して、クラスを設計した方法は正しいです。または 2. Id 整数を文字列 (編集ボックス) に割り当てるのが間違っています。