Created
April 20, 2012 03:20
-
-
Save atljeremy/2425650 to your computer and use it in GitHub Desktop.
Project 3 AOC - ViewController.m - Full Sail
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "ViewController.h" | |
@interface ViewController () | |
@end | |
@implementation ViewController | |
- (void)viewDidLoad | |
{ | |
[super viewDidLoad]; | |
// Do any additional setup after loading the view, typically from a nib. | |
} | |
-(void)viewDidAppear:(BOOL)animated{ | |
[self showStringDialog]; | |
} | |
//FUNCTIONS | |
- (void)showStringDialog { | |
//APPEND | |
//Call the Append function with two NSStrings. Capture the result and display a UIAlertView with the appended string using displayAlertWithString. | |
NSString *myAppendString = [self append:@"Shanna " with:@"Cote"]; | |
[self displayAlertWithString:myAppendString andTitle:@"String Alert"]; | |
} | |
- (void)showCompareStringDialog { | |
//COMPARE | |
//Return true or false based on whether the values are equal. | |
//Call the Compare function with two integer values. If Compare returns true, display an UIAlertView both with the input values and the result using the DisplayAlertWithString function. Take the passed in NSString and display it in the alert view | |
int int1 = 5; | |
int int2 = 5; | |
BOOL compareNum = [self compare:int1 with:int2]; | |
NSString *myCompareString = [NSString stringWithFormat:@"Are the numbers %d and %d equal to each other? %@", int1, int2, compareNum?@"YES":@"NO"]; | |
[self displayAlertWithString:myCompareString andTitle:@"Compare Alert"]; | |
} | |
- (void)showNumberDialog { | |
//ADD | |
//Call the Add function passing in two integer values. Capture the return of this function into a variable. Bundle the returned integer into an NSNumber and then convert it to a NSString and pass it to the DisplayAlertWithString function.Give it any text for the title. The message will read, "The number is 00". Replace the 00 with the integer passed into the function. | |
int sum = [self add:475 with:19]; | |
NSNumber *numberSum = [[NSNumber alloc] initWithInt:sum]; | |
NSString *theNumTxt = [NSString stringWithFormat:@"The number is "]; | |
NSString *numberToString = [numberSum stringValue]; | |
NSString *myNumAddString = [self append:theNumTxt with:numberToString]; | |
[self displayAlertWithString:myNumAddString andTitle:@"Number Alert"]; | |
} | |
//ADD | |
-(int)add:(int)num1 with:(int)num2{ | |
return num1 + num2; | |
} | |
//COMPARE | |
-(BOOL)compare:(int)num1 with:(int)num2{ | |
if (num1 == num2) { | |
return YES; | |
}else{ | |
return NO; | |
} | |
} | |
//APPEND | |
//Create a function called Append. This function will take two NSStrings and return a new NSString containing the appended strings using an NSMutableString and the Append method. | |
-(NSString *)append:(NSString *)string1 with:(NSString *)string2{ | |
NSMutableString *appendedString = [NSMutableString stringWithString:string1]; | |
NSString *string = [appendedString stringByAppendingString:string2]; | |
return string; | |
} | |
//UIAlertView | |
//Create a function called DisplayAlertWithString. This function will take as a parameter an NSString. Create an NSAlertView (I think this needs to be changed to UIAlertView ?? in the assignment?) | |
-(void)displayAlertWithString:(NSString *)string andTitle:(NSString *)title{ | |
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title message:string delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil]; | |
[alert show]; | |
} | |
- (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { | |
// the user clicked one of the OK/Cancel buttons | |
if (buttonIndex == 0) | |
{ | |
if (actionSheet.title == @"String Alert"){ | |
NSLog(@"String Alert"); | |
[self showCompareStringDialog]; | |
} | |
if (actionSheet.title == @"Compare Alert"){ | |
NSLog(@"Compare Alert"); | |
[self showNumberDialog]; | |
} | |
if (actionSheet.title == @"Number Alert"){ | |
NSLog(@"Number Alert"); | |
} | |
} | |
} | |
- (void)viewDidUnload | |
{ | |
[super viewDidUnload]; | |
// Release any retained subviews of the main view. | |
} | |
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation | |
{ | |
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { | |
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); | |
} else { | |
return YES; | |
} | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment