我需要访问UIView数组项(其中所有UIView都有自己的独立活动)。但是在分配为@property (assign, nonatomic) UIView *ui_view[MAXIMUM_UIVIEW];
时,会导致构建失败。
无论如何要让它以我正在尝试的方式或其他更好的方式工作?
错误:
CODE:
#import "ViewController.h"
const int MAXIMUM_UIVIEW = 50;
@interface ViewController ()
@property (assign, nonatomic) UIView *ui_view[MAXIMUM_UIVIEW];
@property (assign, nonatomic) NSInteger phone_height;
@property (assign, nonatomic) NSInteger phone_width;
-(void)func_draw_wall:(int)argument_count;
@end
@implementation ViewController
-(void)ui_button_submit:(UIButton*)sender {
int __chronological__;
//UIView *ui_view[MAXIMUM_UIVIEW];
//int phone_height = self.view.frame.size.height;
//int phone_width = self.view.frame.size.width;
int phone_height = self.view.frame.size.height;
int phone_width = self.view.frame.size.width;
self.phone_height = phone_height;
self.phone_width = phone_width;
for (__chronological__ = 0 ; __chronological__ <= 50 ; __chronological__++ ) {
[self func_draw_wall:__chronological__];
}
}
-(void)func_draw_wall:(int)__chronological__ {
self.ui_view[__chronological__] =
[[UIView alloc] initWithFrame:CGRectMake(0, 0, 50,50)];
[self.view addSubview:self.ui_view[__chronological__]];
NSLog(@"Mem Address of localView[%d] = %x\n", __chronological__, self.ui_view);
}
-(void)ui_button {
self.view.backgroundColor = [UIColor blackColor];
UIButton *but = [[UIButton alloc] init];
[but setTitle:@"--- Add ---" forState:UIControlStateNormal];
[but setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
[but addTarget:self action:@selector(ui_button_submit:)
forControlEvents:UIControlEventTouchUpInside];
int startHeight = 167;
int frameHeight = self.view.frame.size.height - startHeight;
[but setFrame:CGRectMake(0, startHeight, 320, frameHeight)];
[but setTranslatesAutoresizingMaskIntoConstraints:false];
[but setImage:[UIImage imageNamed:@"Image"] forState:UIControlStateNormal];
[self.view addSubview:but];
NSDictionary *viewsDict = @{@"button" : but};
[self.view addConstraints:[NSLayoutConstraint
constraintsWithVisualFormat:@"V:[button]-0-|"
options:0 metrics:nil views:viewsDict]];
NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:but
attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual
toItem:self.view attribute:NSLayoutAttributeCenterX multiplier:1.0
constant:0];
constraint.active = true;
[self.view addConstraint:constraint];
[self.view layoutIfNeeded];
}
- (void)viewDidLoad {
[super viewDidLoad];
[self ui_button];
}
@end
答案 0 :(得分:4)
输入NSArray *
类型,而不是UIView *[]
您应该能够使用泛型类型参数,因此NSArray<UIView *> *