2014-03-03 71 views
1

我有這個數組子視圖:如何使用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>> 

通過我想不通我怎麼能過濾由tag.Any的意見,你知道如何我可以通過標籤子視圖的濾鏡陣列?

回答

1
UIView *mainView = self.view; 

NSArray *subViews = [mainView subViews]; 
NSPredicate *predicate = [NSPredicate predicateWithFormat: @"self.tag in %@", @[@101, @102, @103]]; 
NSArray *filteredViews = [subViews filteredArrayUsingPredicate: predicate]; 
+0

在此行NSPredicate *謂詞= [NSPredicate predicateWithFormat: 「在%d self.tag」,[@ 101 ,@ 102,@ 103]];我收到錯誤:預期標識符 – user2924482

+0

使用%@代替%d – vokilam

2

我弄清楚:

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

你會被反對與標籤跟蹤您的看法?

設置標籤: self.nameLabel.tag = 13

檢索與標籤的視圖: UILabel *myLabel = (UILabel *)[UIView viewWithTag:13];