Here I brought some of the doubt when I used to learn Objective-C and I have searched Google not able to get the perfect answer. I did this from one blog for beginners for Objective-C.
First I will show my code:
@implementation ViewController
@synthesize textfield 1;
@synthesize textfield 2;
@synthesize textfield 3;
@synthesize totalTextField;
- (void)viewDidLoad {
[super viewDidLoad];
// // Do any additional setup after loading the view.
self.navigationItem.title = @“calculate the 3 field“;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)calculate:(id)sender {
int firstNumber = [[self.textfield 1 text] intValue];
int secondNumber = [[self.textfield 2 text] intValue];
int thirdNumber = [[self.textfield 3 text] intValue];
//NSLog(@"firstNumber: %i , secondNumber: %i, thirdNumber: %i", firstNumber, secondNumber, thirdNumber);
float total = (CGFloat) firstNumber/2 + secondNumber/2 + thirdNumber/2;
NSLog(@“total is: %f", total);
NSString *mark = [NSString stringWithFormat:@"%.2f", total];
self.totalTextField.text = mark;
}
Explaniation:
I have three text field called textfield 1,textfield 2,textfield 3
. When the user enters a number in the three text fields they have to press the calculate button. After that some calculation will go and display the final result in totalTextField
.
My questions:
Why in Xcode the default files called
Appdelegate, view controller.
? What is the actual meaning for that two? Why they are default and what will happen if we removeAppdelegate.h .m
files? What is the meaning forviewcontroller, Appdelegate
?In my above code they use inside calculate button method:
int firstNumber = [[self.textfield 1 text] intValue];
why they din't use:
NSInteger * soemname = // alloc init //
And also they used
float
. Why can't useCGFloat
?
Can any one tell me why they used int
instead of NSInteger
and all? And if it is possible can any one recode that int
with NSInteger
to work as same?
Please help me to clear this doubt. I am newbie in learning process.