Я создал 5 UIView динамически, который состоит из одного UILabel и одного UIButton каждый. Когда я нажимаю кнопку, UIView будет setHidden. Но он работает только на одном не другом четырех uiviews.UnEven Поведение UIView при setHidden
@interface ViewController : UIViewController
{
NSMutableArray *newViews;
}
@property(nonatomic,retain)IBOutlet UILabel *welcome;
@property(nonatomic,retain)CustomView *custom;
-(void)buttonPressed:(UIButton *)sender;
@end
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *[email protected]"string of length";
int length=[name length];
newViews = [NSMutableArray array];
NSMutableArray *myArray = [NSMutableArray arrayWithObjects:@"cricket", @"golf",@"wrestling", @"FootBall is good game", nil];
int yAxis=44;
int lengthOfArray=[myArray count];
for(int a=0; a<=lengthOfArray; a++){
self.custom= [[CustomView alloc]initWithFrame:CGRectMake(20, yAxis, 100, 44)];
yAxis=yAxis+50;
NSLog(@"yaxis is %i",yAxis);
self.custom.tag=200+a;
[newViews addObject:self.custom];
self.custom.Label = [[UILabel alloc]initWithFrame:CGRectMake(5,5, length+70, 30)];
self.custom.button=[[UIButton alloc]initWithFrame:CGRectMake(85,10,12,10)];
UIImage *btnImage = [UIImage imageNamed:@"button_droparrow.png"];
[self.custom.button setImage:btnImage forState:UIControlStateNormal];
[self.custom.button addTarget:self action:@selector(buttonPressed:)forControlEvents:UIControlEventTouchDown];
self.custom.button.tag=self.custom.button.tag+a;
self.custom.backgroundColor=[UIColor greenColor];
[email protected]"welcome";
custom.Label.backgroundColor = [UIColor yellowColor];
[self.custom addSubview:self.custom.button];
[self.custom addSubview:custom.Label];
[self.view addSubview:self.custom];
}
[self.custom.button addTarget:self action:@selector(buttonPressed:)forControlEvents:UIControlEventTouchDown];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
-(void)buttonPressed:(UIButton *)sender
{
[self.custom setHidden:YES];
}
@end
Просьба помочь. Я новичок в разработке iOS. Мне нужно здесь, чтобы создать UIView с ссылкой differrnt, и эта ссылка назначает UIButton, чтобы закрыть этот конкретный UIView, но я не смог получить результат.
Вы только скрываете 'self.custom', который заканчивается тем, что указывается только на последний созданный вами CustomView. – rmaddy
да, это была проблема, как я создаю ссылку для каждого uivew, которая была проблемой, но вживую ... –