0

私がやろうとしていることが可能かどうかわからないので、ここである種の構造化の問題に直面しています:

マシン コードから変換された命令の種類を表す 3 つのカスタム クラスがあります。各クラスには、命令の機能やオペランドなどのプロパティがあります。それらは初期化され、3 番目の VC でインスタンスに変換され、NSMutableArray に配置され、その NSMutableArray を 4 番目の VC に正常に移動しました。ここで、配列の各オブジェクトをループ処理して (それがどのタイプのクラスかは不明)、その「命令」プロパティ (つまり NSString) にアクセスする必要があります。それは可能ですか?

クラスの 1 つの宣言例:

@interface iInstruction : NSObject

@property (strong) NSString *opCode;
@property (strong) NSString *rs;
@property (strong) NSString *rt;
@property (strong) NSString *immediate;
@property (strong) NSMutableString *instruction;

- (id) initWithBinary: (NSString *) binaryInstruction;

インスタンスを作成して 4 番目の VC に移動する方法:

iInstruction *NewI = [[iInstruction alloc] initWithBinary:binary32Bits];
[TranslatedCode appendFormat:@"%@\n", NewI.instruction];
[instructions addObject: NewI];

disassembledCode.text = TranslatedCode;
FourthViewController *theVCMover = [self.tabBarController.viewControllers objectAtIndex:3];
theVCMover.instructionsInfo = instructions;

私がやろうとしていることの失敗した試み:

for (NSUInteger i=0; i < [instructionsInfo count]; i++) {   //instructionsInfo is a property of the fourth VC that I use to move the main array from the third VC
    NSString *function = [instructionsInfo objectAtIndex:i].instruction;  //Of course it says property not found because it only receives the NSMutableArray at runtime

    if (function isEqualToString:@"andi") {
    }
4

1 に答える 1

0

これを試して:

for (iInstruction *instruction in self.instructionsInfo) {
    NSString *function = instruction.instruction;

    // and the rest
}

または、ループカウンターが必要な場合:

for (NSUInteger i = 0; i < self.instructionsInfo.count; i++) {
    iInstruction *instruction = self.instructionInfo[i];
    NSString *function = instruction.instruction;

    // and the rest
}

編集:配列にはさまざまなオブジェクトを含めることができるように見えますが、それらはすべてinstructionプロパティを持っているため、これを行うことができます:

for (id obj in self.instructionsInfo) {
    NSString *function = [obj valueForKey:@"instruction"]; // use key-value coding

    // and the rest
}
于 2013-03-28T02:21:43.970 に答える