0
간단한 견적 생성기를 조합하여 견적을 배열에 저장했습니다. 다음은 견적보기 컨트롤러 인터페이스 및 구현 파일입니다 ViewController.h버튼을 클릭해도 아무런 반응이 없습니다. 견적이 변경되지 않습니다
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@property(nonatomic, retain)NSArray *myQuotes;
@property(nonatomic, retain)NSMutableArray *movieQuotes;
@property (nonatomic, retain) IBOutlet UITextView *quote_text;
-(IBAction)quote_btn_touch:(id)sender;
@end
ViewController.m XIB 파일에서
#import "ViewController.h"
@interface ViewController()
@end
@implementation ViewController
@synthesize myQuotes;
@synthesize movieQuotes;
@synthesize quote_text;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.myQuotes = [NSArray arrayWithObjects:
@"Live and let live",
@"Don't cry over spilt milk",
@"Always look on the bright side of life",
@"Nobody's perfect",
@"Can't see the woods for the trees",
@"Better to have loved and lost than not loved at all",
@"The early bird catches the worm",
@"As slow as a wet week",
nil];
quote_text = nil;
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
-(IBAction)quote_btn_touch:(id)sender {
// 1 - Get number of rows in array
int array_tot = [self.myQuotes count];
// 2 - Get random index
int index = (arc4random() % array_tot);
// 3 - Get the quote string for the index
NSString *my_quote = [self.myQuotes objectAtIndex:index];
// 4 - Display the quote in the text view
self.quote_text.text = [NSString stringWithFormat:@"Quote:\n\n%@", my_quote];
}
@end
, 나는 파일의에 텍스트 뷰와 버튼을 연결 소유자, 각각 quote_text 및 quote_btn_touch 사용.
문제는 내가 버튼을 클릭해도 아무 일도 일어나지 않는다는 것입니다. 내가 놓친 어떤 생각?
미리 감사드립니다.
고마워. viewDidLoad 대신 viewDidUnload 메서드 아래에 배치해야합니다. 다시 한 번 감사드립니다! – pdenlinger