如何在UIScrollView中识别视图对象?

时间:2014-02-28 16:31:06

标签: ios uiscrollview tags

我有一个UIScrollView有很多对象,我想识别它们中的每一个。我目前正在执行以下操作:

[learnLabel setTag:currentScrollElements];    
[learnStartButton setTag:currentScrollElements+10000];
[learnLike1Button setTag:currentScrollElements+20000];
[learnLike3Button setTag:currentScrollElements+30000];
[learnCommentField setTag:currentScrollElements+40000];

理想的解决方案是一个系统,我可以将两个相同的数字分配给两个不同的对象(例如,UIButtonUILabel。我不想用完空间,因为标签的最大值与整数的最大值相同。我怎么能这样做?

3 个答案:

答案 0 :(得分:0)

可以将所有对象存储在NSDictionary中。

答案 1 :(得分:0)

你可以这样做。

#define LearnLabel          @"LearnLabel"
#define LearnStartButton    @"LearnStartButton"
#define LearnLike1Button    @"LearnLike1Button"
#define LearnLike3Button    @"LearnLike3Button"
#define LearnCommentField   @"LearnCommentField"
...
...
...


NSMutableDictionary* childObjectsDictionary = [[NSMutableDictionary alloc] init];
[childObjectsDictionary setObject:learnLabel forKey:LearnLabel];
[childObjectsDictionary setObject:learnStartButton forKey:LearnStartButton];
[childObjectsDictionary setObject:learnLike1Button forKey:LearnLike1Button];
[childObjectsDictionary setObject:learnLike3Button forKey:LearnLike3Button];
[childObjectsDictionary setObject:learnCommentField forKey:LearnCommentField];
...
...
...

答案 2 :(得分:0)

理论上,您可以毫无问题地使用标签,因为它可以使用比设备可能的最大功能更多的视图。

但在处理了大量不同的观点后, 将完全令人困惑难以进行管理。

您最好的选择是使用数组或词典,或者更好的是,重新设计您的视图结构并使用内置更好的内存管理支持的UITableViewUICollectionView