クラスをサブクラスUIView
化し、このクラスの複数のインスタンスをループで作成します (毎回インクリメントします)。しかし、ビューのタグを設定しようとすると、それらがすべて作成された後にコンソールにログが記録されます。タグの設定に関係なく、タグは 1 です。
助けていただければ幸いです、ありがとう!
サブビューを作成するための私のコードは次のとおりです。
//for() loop above with i as counter
FlashCardView *subview = [[FlashCardView alloc] initWithFrame:frame];
subview.delegate = self;
subview.viewNum=i+10; //My attempt at a workaround but I cannot get the view with this later so it is not very helpful
[subview setTag:i+10]; //Tried this and subview.tag=i+10;
NSLog(@"%d", subview.tag); //Prints correctly
//Gets added to parent later
これNSLog
は正しいタグをログに記録しますが、UIView
サブクラスでタグをログに記録すると、常にタグが として返され1
ます。また、後で呼び出されたメソッドで親のすべてのサブビューを印刷すると ( でviewcontroller
)、それらすべてにタグ 1 が付けられます。