Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/95.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在ios中使用快速枚举从scrollview的所有子视图中获得固定数量的子视图_Ios_Scrollview_Subview_Nsfastenumeration - Fatal编程技术网

如何在ios中使用快速枚举从scrollview的所有子视图中获得固定数量的子视图

如何在ios中使用快速枚举从scrollview的所有子视图中获得固定数量的子视图,ios,scrollview,subview,nsfastenumeration,Ios,Scrollview,Subview,Nsfastenumeration,如何在ios中使用快速枚举从scrollview的所有子视图中选择固定数量的子视图?执行以下操作: 1.在创建按钮时为按钮提供标记。例如: UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; button.tag = 1; [button addTarget:self action:@selector(aMethod:) forControlEvents:UIControlEventTouchU

如何在ios中使用快速枚举从scrollview的所有子视图中选择固定数量的子视图?

执行以下操作: 1.在创建按钮时为按钮提供标记。例如:

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.不理解为什么要使用快速枚举,可以通过以下方式简单获取按钮:

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];
        }
    }
}
NSMutableArray*arrayOfButtons=[[NSMutableArray alloc]initWithCapacity:5];
for(self.yourcollview.subview中的id btn)
{
@自动释放池{

如果(btn.tag>0 | | btn.tag请提供详细说明-您想要实现什么,您做了什么,您面临什么问题,您希望做什么。我有一个scrollview,由十个动态生成的按钮组成。我只想使用快速枚举访问scrollview中的前5个按钮。因此,请提供一些解决方案,以便仅获取循环中的5个按钮,如“for(UIButton*btn in scrollview)”。请提供更多详细信息