gpt4 book ai didi

ios - 快捷代码(根据数量隐藏 View )

转载 作者:行者123 更新时间:2023-11-29 11:48:18 25 4
gpt4 key购买 nike

下面的最佳代码是什么,代码运行良好,没有问题,我正在寻找一种更好的代码编写方式,有 11 个 View 和一定数量的用户,所以我需要隐藏 View 基于 11 个可用的用户假设我们有 11 个用户,只有 2 个可用,所以它将是 11 个中的 2 个。该应用程序将隐藏第一个 View 和第二个 View ,但不会隐藏从 3 到 11 的 View ,依此类推

    NSInteger countOfViews = 2;
if (countOfViews == 1) {
UIView *viewtag1 = (UIView *)[self.leftScrollView viewWithTag:1000];
UIView *viewtag2 = (UIView *)[self.leftScrollView viewWithTag:2000];
UIView *viewtag3 = (UIView *)[self.leftScrollView viewWithTag:3000];
UIView *viewtag4 = (UIView *)[self.leftScrollView viewWithTag:4000];
UIView *viewtag5 = (UIView *)[self.leftScrollView viewWithTag:5000];
UIView *viewtag6 = (UIView *)[self.leftScrollView viewWithTag:6000];
UIView *viewtag7 = (UIView *)[self.leftScrollView viewWithTag:7000];
UIView *viewtag8 = (UIView *)[self.leftScrollView viewWithTag:8000];
UIView *viewtag9 = (UIView *)[self.leftScrollView viewWithTag:9000];
UIView *viewtag10 = (UIView *)[self.leftScrollView viewWithTag:10000];
UIView *viewtag11 = (UIView *)[self.leftScrollView viewWithTag:11000];

viewtag1.hidden = YES;
viewtag2.hidden = NO;
viewtag3.hidden = NO;
viewtag4.hidden = NO;
viewtag5.hidden = NO;
viewtag6.hidden = NO;
viewtag7.hidden = NO;
viewtag8.hidden = NO;
viewtag9.hidden = NO;
viewtag10.hidden = NO;
viewtag11.hidden = NO;
}


if (countOfViews == 2) {
UIView *viewtag1 = (UIView *)[self.leftScrollView viewWithTag:1000];
UIView *viewtag2 = (UIView *)[self.leftScrollView viewWithTag:2000];
UIView *viewtag3 = (UIView *)[self.leftScrollView viewWithTag:3000];
UIView *viewtag4 = (UIView *)[self.leftScrollView viewWithTag:4000];
UIView *viewtag5 = (UIView *)[self.leftScrollView viewWithTag:5000];
UIView *viewtag6 = (UIView *)[self.leftScrollView viewWithTag:6000];
UIView *viewtag7 = (UIView *)[self.leftScrollView viewWithTag:7000];
UIView *viewtag8 = (UIView *)[self.leftScrollView viewWithTag:8000];
UIView *viewtag9 = (UIView *)[self.leftScrollView viewWithTag:9000];
UIView *viewtag10 = (UIView *)[self.leftScrollView viewWithTag:10000];
UIView *viewtag11 = (UIView *)[self.leftScrollView viewWithTag:11000];

viewtag1.hidden = YES;
viewtag2.hidden = YES;
viewtag3.hidden = NO;
viewtag4.hidden = NO;
viewtag5.hidden = NO;
viewtag6.hidden = NO;
viewtag7.hidden = NO;
viewtag8.hidden = NO;
viewtag9.hidden = NO;
viewtag10.hidden = NO;
viewtag11.hidden = NO;
}

/*
till if (countOfViews == 11)
*/

最佳答案

    NSInteger countOfViews = 2;
for (int i = 1; i <= 11; i++) {
UIView *view = (UIView *)[self.leftScrollView viewWithTag:i * 1000];
view.hidden = (i <= countOfViews);
}

关于ios - 快捷代码(根据数量隐藏 View ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42360271/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com