如何使用 NSPredicate 通过标签过滤子视图的 NSArray? [英] How to filter a NSArray of subviews by tag using NSPredicate?

查看:48
本文介绍了如何使用 NSPredicate 通过标签过滤子视图的 NSArray?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个子视图数组:

<UIButton: 0xa2b1600; frame = (41 20; 42 30); opaque = NO; autoresize = RM+BM; layer = <CALayer: 0xa2b06e0>>,
<UIButton: 0xa2b1290; frame = (121 694; 69 30); opaque = NO; autoresize = RM+BM; layer = <CALayer: 0xa2b0dc0>>,
<SequenceViews: 0xb16fba0; frame = (62 393; 280 323); tag = 100; gestureRecognizers = <NSArray: 0xb16dc90>; animations = { position=<CASpringAnimation: 0xb16c990>; }; layer = <CALayer: 0xb168880>>,
<SequenceViews: 0xb171c30; frame = (62 52; 280 323); tag = 101; gestureRecognizers = <NSArray: 0xb176290>; animations = { position=<CASpringAnimation: 0xb16bb50>; }; layer = <CALayer: 0xb173980>>,
<SequenceViews: 0xb17d430; frame = (372 222; 280 323); tag = 102; gestureRecognizers = <NSArray: 0xb17d140>; animations = { position=<CASpringAnimation: 0xb176070>; }; layer = <CALayer: 0xb16b060>>,
<SequenceViews: 0xb178ba0; frame = (682 393; 280 323); tag = 104; gestureRecognizers = <NSArray: 0xb178e80>; animations = { position=<CASpringAnimation: 0xb180680>; }; layer = <CALayer: 0xb1795c0>>,
<SequenceViews: 0xb16a9f0; frame = (682 52; 280 323); tag = 105; gestureRecognizers = <NSArray: 0xb1819d0>; animations = { position=<CASpringAnimation: 0xb16aad0>; }; layer = <CALayer: 0xb182710>>

我不知道如何按标签过滤视图.有谁知道我如何按标签过滤子视图数组?

By I can not figure out how can I filter the views by tag.Any of you knows how I can filter the array of subviews by tag?

推荐答案

我明白了:

NSPredicate *tagPredicate = [NSPredicate predicateWithFormat:@"self.tag >= 100"];
NSArray *resultArray = [[self.view subviews] filteredArrayUsingPredicate:tagPredicate];

这篇关于如何使用 NSPredicate 通过标签过滤子视图的 NSArray?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆