guguquizAppDelegate.h
#import <UIKit/UIKit.h>
@interface guguquizAppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) IBOutlet UIWindow *window;
@property (strong, nonatomic) IBOutlet UITabBarController *tabController;
@end
#import "guguquizAppDelegate.h"
@implementation guguquizAppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// // Override point for customization after application launch.
// self.window.backgroundColor = [UIColor whiteColor];
self.window.rootViewController = self.tabController;
[self.window makeKeyAndVisible];
return YES;
}
#import <UIKit/UIKit.h>
@interface GugudnaListViewController : UIViewController<UITableViewDataSource, UITableViewDelegate>
@end
#import "GugudnaListViewController.h"
@interface GugudnaListViewController ()
@end
@implementation GugudnaListViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
#pragma - UITableView handler
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 9;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 9; // 단수 출력
}
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return [NSString stringWithFormat:@"%d 단", section + 1];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *identify = @"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identify];
if(cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identify];
}
cell.textLabel.text = [NSString stringWithFormat:@"%d x %d", (indexPath.section + 1), (indexPath.row + 1)];
cell.detailTextLabel.text = [NSString stringWithFormat:@"%d", (indexPath.section + 1) * (indexPath.row + 1)];
return cell;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = @"구구단 리스트";
// Do any additional setup after loading the view from its nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
#import <UIKit/UIKit.h>
@interface StartQuizViewController : UIViewController
- (IBAction)onStart:(id)sender;
@end
#import "StartQuizViewController.h"
#import "QuizViewController.h"
@interface StartQuizViewController ()
@end
@implementation StartQuizViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = @"구구단 퀴즈";
// Do any additional setup after loading the view from its nib.
}
- (IBAction)onStart:(id)sender
{
QuizViewController *viewController = [[QuizViewController alloc] initWithNibName:@"QuizViewController" bundle:nil];
[self.navigationController pushViewController:viewController animated:YES];
viewController.totalQuiz = 10;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
#import <UIKit/UIKit.h>
@class StartQuizViewController;
@interface QuizViewController : UIViewController
{
UILabel *labelFirst;
UILabel *labelSecond;
UITextField *testAnswer;
NSInteger numAnswer;
StartQuizViewController *mainViewController;
}
@property NSInteger totalQuiz;
@property NSInteger correctAnswer;
@property NSInteger wrongAnswer;
@property (nonatomic, retain) IBOutlet UITextField *textAnswer;
@property (nonatomic, retain) IBOutlet UILabel *labelFirst;
@property (nonatomic, retain) IBOutlet UILabel *labelSecond;
@property (nonatomic, retain) IBOutlet UILabel *labelMark;
- (void)onCheckAnswerAndNext;
- (void)putTheQuiz;
@end
#import "QuizViewController.h"
#import "ResultViewController.h"
@interface QuizViewController ()
@end
@implementation QuizViewController
@synthesize totalQuiz;
@synthesize correctAnswer;
@synthesize wrongAnswer;
@synthesize textAnswer;
@synthesize labelFirst;
@synthesize labelSecond;
@synthesize labelMark;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)putTheQuiz
{
int gugu_1 = arc4random() % 8 + 1;
int gugu_2 = arc4random() % 8 + 1;
labelFirst.text = [NSString stringWithFormat:@"%d", gugu_1];
labelSecond.text = [NSString stringWithFormat:@"%d", gugu_2];
numAnswer = gugu_1 * gugu_2;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
[self putTheQuiz];
[self.textAnswer becomeFirstResponder];
// next button
UIBarButtonItem *nextButton = [[UIBarButtonItem alloc] initWithTitle:@"다음" style:UIBarButtonItemStyleDone target:self action:@selector(onCheckAnswerAndNext)];
self.navigationItem.rightBarButtonItem = nextButton;
self.title = [NSString stringWithFormat:@"문제 %d", self.correctAnswer + self.wrongAnswer + 1];
}
- (void)viewDidAppear:(BOOL)animated
{
NSMutableArray *views = [[NSMutableArray alloc] initWithArray:self.navigationController.viewControllers];
if([views count] > 1 && [[views objectAtIndex:[views count] -2] isKindOfClass:[QuizViewController class]])
{
// 이전 QuizViewController를 제거한다.
[views removeObjectAtIndex:[views count] - 2];
self.navigationController.viewControllers = views;
}
}
- (void)onCheckAnswerAndNext
{
if([textAnswer.text intValue] == numAnswer)
{
self.correctAnswer++;
self.labelMark.text = @"O";
}
else
{
self.wrongAnswer++;
[labelMark setTextColor:[UIColor redColor]];
self.labelMark.text = @"X";
}
// animation
self.labelMark.hidden = NO;
self.labelMark.alpha = 0.0f;
[UIView animateWithDuration:0.5f animations:^{self.labelMark.alpha = 1.0f;} completion:^(BOOL finished)
{
//화면전환
if(self.totalQuiz == self.correctAnswer + self.wrongAnswer)
{
ResultViewController *viewController = [[ResultViewController alloc] initWithNibName:@"ResultViewController" bundle:nil];
viewController.totalQuiz = self.totalQuiz;
viewController.correctAnswer = self.correctAnswer;
[self.navigationController pushViewController:viewController animated:YES];
}
else
{
QuizViewController *viewController = [[QuizViewController alloc] initWithNibName:@"QuizViewController" bundle:nil];
viewController.totalQuiz = self.totalQuiz;
viewController.correctAnswer = self.correctAnswer;
viewController.wrongAnswer = self.wrongAnswer;
[self.navigationController pushViewController:viewController animated:YES];
}
self.title = @"구구단 퀴즈";
}];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
#import <UIKit/UIKit.h>
@interface ResultViewController : UIViewController
@property NSInteger totalQuiz;
@property NSInteger correctAnswer;
@property (retain, nonatomic) IBOutlet UILabel *labelTotalQuiz;
@property (retain, nonatomic) IBOutlet UILabel *labelCorrectAnswer;
@property (retain, nonatomic) IBOutlet UILabel *labelMessage;
@end
#import "ResultViewController.h"
#import "QuizViewController.h"
@interface ResultViewController ()
@end
@implementation ResultViewController
@synthesize totalQuiz;
@synthesize correctAnswer;
@synthesize labelTotalQuiz;
@synthesize labelCorrectAnswer;
@synthesize labelMessage;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
self.labelTotalQuiz.text = [NSString stringWithFormat:@"%d", self.totalQuiz];
self.labelCorrectAnswer.text = [NSString stringWithFormat:@"%d", self.correctAnswer];
NSString *message = @"";
float score = (float)correctAnswer / (float)totalQuiz * 100.0f;
if(score == 100.0)
{
message = @"참 잘했어요. ";
}
else if(score > 80.0f)
{
message = @"잘했어요. ";
}
else if(score > 60.0f)
{
message = @"노력 좀 하셔야 겠네요. ";
}
else if(score > 40.0f)
{
message = @"부모님이 걱정하십니다. ";
}
else if(score > 20.0f)
{
message = @"아직 희망이 있어요. ";
}
else
{
message = @"이를 어쩌나... ";
}
self.labelMessage.text = message;
}
- (void)viewDidAppear:(BOOL)animated
{
NSMutableArray *views = [[NSMutableArray alloc] initWithArray:self.navigationController.viewControllers];
if([views count] > 1 && [[views objectAtIndex:[views count] - 2] isKindOfClass:[QuizViewController class]])
{
// 이전 QuizViewController를 제거한다.
[views removeObjectAtIndex:[views count] - 2];
self.navigationController.viewControllers = views;
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
'Programing > IOS' 카테고리의 다른 글
SQL 을 이용한 DB프로그램 테이블에 뿌리기 (0) | 2013.10.07 |
---|---|
세그먼트 연습 (0) | 2013.10.04 |
선, 사각형 등 도형 그리기 연습 (0) | 2013.10.04 |
타이머를 이용한 레이블에 시간표시 하는 방법 (0) | 2013.10.01 |
SQLite를 이용한 간단한 DB프로그램 (0) | 2013.09.30 |