0
如何使用ios中的快速枚舉從滾動視圖的所有子視圖中選擇子視圖的固定數量?如何使用滾動視圖的所有子視圖中使用ios中的快速枚舉獲取固定數量的子視圖
如何使用ios中的快速枚舉從滾動視圖的所有子視圖中選擇子視圖的固定數量?如何使用滾動視圖的所有子視圖中使用ios中的快速枚舉獲取固定數量的子視圖
做如下: 確定公司運作的標籤,你的按鈕,當你創建them.for例如:
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.tag = 1;
[button addTarget:self
action:@selector(aMethod:)
forControlEvents:UIControlEventTouchUpInside];
[button setTitle:@"Show View" forState:UIControlStateNormal];
button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0);
[view addSubview:button];
2.do不明白你爲什麼要使用快速列舉,你可以簡單的讓你通過按鈕:
UIButton *btn1 = (UIButton *)[self.yourScrollView viewWithTag:1];
UIButton *btn2 = (UIButton *)[self.yourScrollView viewWithTag:2];
UIButton *btn3 = (UIButton *)[self.yourScrollView viewWithTag:3];
UIButton *btn4 = (UIButton *)[self.yourScrollView viewWithTag:4];
UIButton *btn5 = (UIButton *)[self.yourScrollView viewWithTag:5];
2.如果你的要求是使用快速枚舉,需要一個NSMutableArray握住你的按鈕:
NSMutableArray *arrayOfButtons = [[NSMutableArray alloc] initWithCapacity:5];
for (id btn in self.yourScrollView.subviews)
{
@autoreleasepool {
if (btn.tag > 0 || btn.tag<=5)
{
[arrayOfButtons addObject:btn];
}
}
}
希望它能幫助你。
請提供詳細說明 - 你想達到什麼,你做了什麼,你面臨什麼問題,你期望做什麼。 – Kampai 2014-10-09 10:30:35
我有一個由十個動態生成的按鈕組成的滾動視圖。我只想使用快速枚舉從滾動視圖訪問前5個按鈕。所以請提供一些解決方案,從循環中只獲取5個按鈕,例如「for(UIButton * btn in scrollview)」。 – 2014-10-09 10:51:13
請提供更多細節varsha – Alok 2014-10-09 10:51:57