我对一个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。