저는 UILabel 하나와 UIButton 하나씩으로 구성된 5 개의 UIView를 동적으로 생성했습니다. 버튼을 클릭하면 UIView가 setHidden이됩니다. 하지만 그것은 다른 4 가지 uiviews에 대해서만 작동합니다. setHidden 일 때의 UnEven UIView 동작
@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 개발에 새로운 사람이다. differrnt 참조 및 그 특정 UIView 닫으려면 UIButton 할당 할 UIView 만들려면 여기에 필요하지만 결과를 얻을 수 없습니다. 각
UIView
에 대한 XIB의 번호와 함께
- (void) buttonPressed: (UIButton*) sender
{
UIView* view = sender.superview;
view.hidden = YES;
}
생성 한 마지막'CustomView '만 가리키는'self.custom'이 숨어 있습니다. – rmaddy
네, 문제가 생겨서 문제가되는 각각의 uivew에 대한 참조를 만드는 방법이 ... –