2013-07-18 2 views
0

이 프로그램을 실행할 때 원하는 결과가 나타나지 않습니다. 내가 작성하려고하는 것은 UITextField에서 사용자로부터 텍스트를 가져 오는 속성 프로그램입니다. 그리고 업데이트 버튼을 클릭하면 텍스트 필드 위의 UILabel에 텍스트가 표시됩니다. 일단 내가 텍스트를 편집 할 수있는 버튼을 추가합니다.UITextField에서 속성이 지정된 문자열을 검색하려면 어떻게합니까?

#import "TextChangerViewController.h" 

@interface TextChangerViewController() 
@property (strong, nonatomic) IBOutlet UITextField *textInput; 
@property (strong, nonatomic) IBOutlet UILabel *textOutput; 
@property (strong, nonatomic) IBOutlet UIButton *updateButton; 


@end 

@implementation TextChangerViewController 


- (void)updateText:(NSAttributedString *)input 
{ 
    [self.textOutput setAttributedText:input]; 
} 
- (IBAction)updateDisplayText:(UIButton *)sender 
{ 

    [self updateText:[[NSAttributedString alloc]initWithString:self.textInput.text]]; 
} 

@end 

답변

0

귀하는 IB를 사용한다고 가정합니다. 그렇지 않다면 나를 바로 잡으십시오.

enter image description here

는 또한 당신의 UILabel의 동일한 방법으로이 작업을 수행 :

이 작업을 수행하는 좋은 쉬운 방법은 IB에서 텍스트 필드를 클릭하고 Text 속성을 변경하는 것입니다. 그런 다음 방법에 :

- (void)updateText:(NSAttributedString *)input 
{ 
    self.textOutput.attributedText = input; 
} 

- (IBAction)updateDisplayText:(UIButton *)sender 
{ 
    [self updateText:self.textInput.attributedText]; 
} 

(난 당신이 알고 확신으로) 당신은 쉽게 하나의 방법으로이 결합 할 수 있지만, 나는 그들이 당신의 예에서와 같이 분리 떠났다. 마지막으로 모든 IBOutlets이 올바르게 연결되어 있는지 확인하십시오.

+0

감사합니다. 그 트릭을 했어! – PeterJLyons

+0

@ user2597389, 기뻤습니다! – Firo

관련 문제