2014-02-21 2 views
0

이 문제는 며칠 동안 당황 스럽습니다.프로그래밍 방식으로 생성 된 UIButton을 숨길 수 없습니다.

두 개의 UIButton이 있습니다. 하나는 스토리 보드를 사용하여 만들고 다른 하나는 프로그래밍 방식으로 만듭니다.

단추 중 하나를 누르면 프로그래밍 방식으로 작성된 단추와 스토리 보드 단추가 모두 숨겨 지지만 스토리 보드 단추 만 사라지는 반면 프로그래밍 방식으로 작성된 단추는 남아 있습니다. 숨기기뿐만 아니라 프로그래밍 방식으로 작성된 버튼의 프레임을 변경하려고 시도했지만 아무 소용이 없습니다. 여기 코드가 사용됩니다

@property (strong, nonatomic) UIButton *catBut; 
@property (weak, nonatomic) IBOutlet UIButton *whenButton; 
.... 
.... 
-(void)viewDidLoad { 
.... 
    [self customizeButton:self.catBut withFrame:CGRectMake(165, 113, 135, 50) 
      andAction:@selector(selectedCat) andColor:[UIColor belizeHoleColor] 
      andTag:2 andImage:@"coffee-64.png" andText:@"Cafes" andAlignmentLeft:YES]; 
.... 
} 

- (void)customizeButton:(UIButton *)but withFrame:(CGRect)rect andAction:(SEL)action 
         andColor:(UIColor *)col andTag:(NSUInteger)tag 
         andImage:(NSString *)imageName 
         andText:(NSString *)buttonText 
         andAlignmentLeft:(BOOL)alignLeft { 
    but = [UIButton buttonWithType:UIButtonTypeCustom]; 
    [but setFrame:rect]; 
    [but setTitle:buttonText forState:UIControlStateNormal]; 
    but.tag = tag; 
    but.titleLabel.numberOfLines = 0; 
    but.titleLabel.font = [UIFont boldFlatFontOfSize:18]; 
    [but setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal]; 
    CGFloat spacing = 10; // the amount of spacing to appear between image and title 
    but.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; 
    but.imageEdgeInsets = UIEdgeInsetsMake(0, spacing, 0, 0); 
    but.titleEdgeInsets = UIEdgeInsetsMake(0, spacing*2, 0, 0); 
    [but setTitleColor:[UIColor cloudsColor] forState:UIControlStateNormal]; 
    [but setTitleColor:[UIColor cloudsColor] forState:UIControlStateHighlighted]; 
    [but addTarget:self action:action forControlEvents:UIControlEventTouchUpInside]; 
    [self.buttonsView addSubview:but]; 
} 
.... 
- (void)selectedCat { 
    self.catBut.hidden = YES; 
    self.whenButton.hidden = YES; 
} 

왜 UI 변경 만 스토리 보드 버튼을 준수? 제가 누락 된 것이 있습니까? 나는 AutoLayout을 취소하려했지만 그 일은 변하지 않았다.

답변

3

문제는 당신의 방법 (customizeButton:(UIButton *)but)에 인수 지나가는입니다. 사용 &self.catBut

+0

당신이 문제를 해결했습니다! 정말 고마워. – Yarneo

+0

나는 그것이 UIButton 포인터의 전달과 관련이 있다는 점에 직감이있었습니다. – Yarneo

+0

문제가 해결되었습니다. – nanjunda

0

BOOL 유형이 아니고 bool 유형입니다.

내가이 속성 catBut을 볼 수있는이

self.catBut.hidden = YES; 
self.whenButton.hidden = YES; 

을 시도하지만 나뿐만 아니라 내가 아울렛을 너무주지 않았다, 이것에 대한 생성을 참조 두지. 이것을 확인하십시오. 당신은 무언가를 시도했지만 단순히 다음 줄을 따라 고쳐야합니다.

[self.buttonsView addSubview:but]; 
self.catBut = but; 
+0

호출하는 동안

이 당신의 코드를 변경하고

but = [UIButton buttonWithType:UIButtonTypeCustom];

self.catBut = [UIButton buttonWithType:UIButtonTypeCustom]; ...... [self.buttonsView addSubview:self.catBut]; 

확인하거나 방법

에 주소 customizeButton:(UIButton **)but를 통과해야하고

감사합니다 iMani,하지만 그게 문제가 아니야. 그에 따라 코드를 수정하십시오. – Yarneo

+0

@ Yarneo 내 업데이트 된 답변보기 – Mani

관련 문제