iphone dev
Post on 30-May-2018
223 Views
Preview:
TRANSCRIPT
-
8/9/2019 Iphone dev
1/42
CS193pSpring 2010
Wednesday, March 31, 2010
-
8/9/2019 Iphone dev
2/42
Enrollment Closed
You should have received an e-mailIt will confirm your grading status (P/NC or not)
As usual, we were oversubscribed for grading option
Sorry to anyone who didnt get the option they wanted
If you received e-mail, but are not in Axess, do it!
... and an invitation to iPhone Developer Program
If not, e-mail cs193p@cs.stanford.edu.
Wednesday, March 31, 2010
mailto:cs193p@cs.stanford.edumailto:cs193p@cs.stanford.edumailto:cs193p@cs.stanford.edu -
8/9/2019 Iphone dev
3/42
Communication
E-mailQuestions are best sent to cs193p@cs.stanford.edu
Sending directly to instructor or TAs risks slow response.
Web SiteVery Important!http://cs193p.stanford.eduAll lectures, assignments, code, etc. will be there.
This site will be your best friend when it comes to getting info.
Wednesday, March 31, 2010
http://cs193p.stanford.edu/http://cs193p.stanford.edu/http://cs193p.stanford.edu/mailto:cs193p@cs.stanford.edumailto:cs193p@cs.stanford.edu -
8/9/2019 Iphone dev
4/42
Office Hours
AndreasMonday 6pm to 8pm
Thursday 6pm to 8pmGates B26A
Bring your Stanford ID card for access to the building
SonaliFriday 11am to 1pm
Thursday 1pm to 3pm
Gates B26B
Wednesday, March 31, 2010
-
8/9/2019 Iphone dev
5/42
Todays Topics
MVCCalculator
Objective-CDeclaring and implementing objects
Sending messages between objects
Interface BuilderWiring up objects to send messages to each otherSetting up the properties of objects
XcodeManaging all your codeRunning your application in the simulator
Wednesday, March 31, 2010
-
8/9/2019 Iphone dev
6/42
Our Calculator
Model View
Controller
CalculatorViewController
CalculatorBrain
UILabel
Wednesday, March 31, 2010
-
8/9/2019 Iphone dev
7/42
@interface
@end
Model
Header File (public API)
Wednesday, March 31, 2010
-
8/9/2019 Iphone dev
8/42
@interface CalculatorBrain
@end
Model
Header File (public API)
Wednesday, March 31, 2010
-
8/9/2019 Iphone dev
9/42
-
8/9/2019 Iphone dev
10/42
#import
@interface CalculatorBrain : NSObject
doubleoperand;{
}
@end
Model
Header File (public API)
Wednesday, March 31, 2010
-
8/9/2019 Iphone dev
11/42
#import
@interface CalculatorBrain : NSObject
doubleoperand;{
}
- (void)setOperand:(double)anOperand;
- (double)performOperation:(NSString *)operation;
@end
Model
Header File (public API)
Wednesday, March 31, 2010
-
8/9/2019 Iphone dev
12/42
Specifying void as the return type meansthat this method returns no value.
#import
@interface CalculatorBrain : NSObject
doubleoperand;{
}
- (void)setOperand:(double)anOperand;
- (double)performOperation:(NSString *)operation;
@end
Model
Header File (public API)
Wednesday, March 31, 2010
-
8/9/2019 Iphone dev
13/42
#import
@interface CalculatorBrain : NSObject
doubleoperand;{
}
- (void)setOperand:(double)anOperand;
- (double)performOperation:(NSString *)operation;
@end
The name of this method is setOperand:
Model
Header File (public API)
Wednesday, March 31, 2010
-
8/9/2019 Iphone dev
14/42
#import
@interface CalculatorBrain : NSObject
doubleoperand;{
}
- (void)setOperand:(double)anOperand;
- (double)performOperation:(NSString *)operation;
@end
It takes one argument, a double called anOperand
Model
Header File (public API)
Wednesday, March 31, 2010
-
8/9/2019 Iphone dev
15/42
#import
@interface CalculatorBrain : NSObject
doubleoperand;{
}
- (void)setOperand:(double)anOperand;
- (double)performOperation:(NSString *)operation;
@end
Dont forget a semicolon here!
Model
Header File (public API)
Wednesday, March 31, 2010
-
8/9/2019 Iphone dev
16/42
#import
@interface CalculatorBrain : NSObject
doubleoperand;{
}
- (void)setOperand:(double)anOperand;
- (double)performOperation:(NSString *)operation;
@end
This method returns a double.
Model
Header File (public API)
Wednesday, March 31, 2010
-
8/9/2019 Iphone dev
17/42
#import
@interface CalculatorBrain : NSObject
doubleoperand;{
}
- (void)setOperand:(double)anOperand;
- (double)performOperation:(NSString *)operation;
@end
It takes a pointer to an NSString object as its argument.Thats right, were passing an object to this method.
Model
Header File (public API)
Wednesday, March 31, 2010
-
8/9/2019 Iphone dev
18/42
#import
@interface CalculatorBrain : NSObject
doubleoperand;{
}
- (void)setOperand:(double)anOperand;
- (double)performOperation:(NSString *)operation;
@end
- (NSArray *)foo:(int)zap bar:(id)pow;
Model
Header File (public API)
Wednesday, March 31, 2010
-
8/9/2019 Iphone dev
19/42
#import
@interface CalculatorBrain : NSObject
doubleoperand;{
}
- (void)setOperand:(double)anOperand;
- (double)performOperation:(NSString *)operation;
@end
- (NSArray *)foo:(int)zap bar:(id)pow;
This method takes two arguments and is called foo:bar:
Model
Header File (public API)
Wednesday, March 31, 2010
-
8/9/2019 Iphone dev
20/42
#import
@interface CalculatorBrain : NSObject
doubleoperand;{
}
- (void)setOperand:(double)anOperand;
- (double)performOperation:(NSString *)operation;
@end
- (NSArray *)foo:(int)zap bar:(id)pow;
It returns a pointer to an NSArray(a collection class in Foundation).
Model
Header File (public API)
Wednesday, March 31, 2010
-
8/9/2019 Iphone dev
21/42
#import
@interface CalculatorBrain : NSObject
doubleoperand;{
}
- (void)setOperand:(double)anOperand;
- (double)performOperation:(NSString *)operation;
@end
- (NSArray *)foo:(int)zap bar:(id)pow;
The second argument is of type idThis means a pointer to *ANY* kind of object!
Model
Header File (public API)
Wednesday, March 31, 2010
-
8/9/2019 Iphone dev
22/42
#import
@interface CalculatorBrain : NSObject
doubleoperand;{
}
- (void)setOperand:(double)anOperand;
- (double)performOperation:(NSString *)operation;
@end
- (NSArray *)foo:(int)zap bar:(id)pow;
Model
Header File (public API)
Wednesday, March 31, 2010
-
8/9/2019 Iphone dev
23/42
#import
@interface CalculatorBrain : NSObject
doubleoperand;{
}
- (void)setOperand:(double)anOperand;
- (double)performOperation:(NSString *)operation;
@end
Model
Header File (public API)
Wednesday, March 31, 2010
-
8/9/2019 Iphone dev
24/42
#import CalculatorBrain.h
@implementation CalculatorBrain
@end
Model
Implementation File(private and public)
Wednesday, March 31, 2010
-
8/9/2019 Iphone dev
25/42
#import CalculatorBrain.h
@implementation CalculatorBrain
@end
- (double)performOperation:(NSString *)operation
{
return aDouble;}
- (void)setOperand:(double)anOperand{
}
Model
Implementation File(private and public)
Wednesday, March 31, 2010
-
8/9/2019 Iphone dev
26/42
#import CalculatorBrain.h
@implementation CalculatorBrain
@end
- (double)performOperation:(NSString *)operation
{
return aDouble;}
- (void)setOperand:(double)anOperand{
}
No semicolon this time!
Model
Implementation File(private and public)
Wednesday, March 31, 2010
-
8/9/2019 Iphone dev
27/42
#import CalculatorBrain.h
@implementation CalculatorBrain
@end
- (double)performOperation:(NSString *)operation
{
return aDouble;}
- (void)setOperand:(double)anOperand{
}
[operation sendMessage:argument];
Model
Implementation File(private and public)
Wednesday, March 31, 2010
-
8/9/2019 Iphone dev
28/42
#import CalculatorBrain.h
@implementation CalculatorBrain
@end
- (double)performOperation:(NSString *)operation
{
return aDouble;}
- (void)setOperand:(double)anOperand{
}
[operation sendMessage:argument];
Square brackets mean send a message.
Model
Implementation File(private and public)
Wednesday, March 31, 2010
-
8/9/2019 Iphone dev
29/42
#import CalculatorBrain.h
@implementation CalculatorBrain
@end
- (double)performOperation:(NSString *)operation
{
return aDouble;}
- (void)setOperand:(double)anOperand{
}
[operation sendMessage:argument];
This is the object to send the message to(in this case, the NSString called operation that was
passed as an argument to performOperation:).
Model
Implementation File(private and public)
Wednesday, March 31, 2010
l t ti il
-
8/9/2019 Iphone dev
30/42
#import CalculatorBrain.h
@implementation CalculatorBrain
@end
- (double)performOperation:(NSString *)operation
{
return aDouble;}
- (void)setOperand:(double)anOperand{
}
[operation sendMessage:argument];
This is the message to send.
Model
Implementation File(private and public)
Wednesday, March 31, 2010
I l t ti Fil
-
8/9/2019 Iphone dev
31/42
#import CalculatorBrain.h
@implementation CalculatorBrain
@end
- (double)performOperation:(NSString *)operation
{
return aDouble;}
- (void)setOperand:(double)anOperand{
}
[operation sendMessage:argument];
And this is its one (in this case) argument.
Model
Implementation File(private and public)
Wednesday, March 31, 2010
-
8/9/2019 Iphone dev
32/42
Controller
@end
:
#import
@interface CalculatorViewController UIViewController
IBOutlet UILabel * display;
{
}
- (IBAction)digitPressed:(UIButton *)sender;
CalculatorBrain * brain;
- (IBAction)operationPressed:(UIButton *)sender;
Wednesday, March 31, 2010
-
8/9/2019 Iphone dev
33/42
Controller
@end
:
#import
@interface CalculatorViewController UIViewController
IBOutlet UILabel * display;
{
}
- (IBAction)digitPressed:(UIButton *)sender;
CalculatorBrain * brain;
- (IBAction)operationPressed:(UIButton *)sender;
Our Controller inherits from
UIViewController. UIKitsupports MVC primarily
through this class.
Wednesday, March 31, 2010
-
8/9/2019 Iphone dev
34/42
Controller
@end
:
#import
@interface CalculatorViewController UIViewController
IBOutlet UILabel * display;
{
}
- (IBAction)digitPressed:(UIButton *)sender;
CalculatorBrain * brain;
- (IBAction)operationPressed:(UIButton *)sender;
This is going to point to ourCalculatorBrain Model
Wednesday, March 31, 2010
-
8/9/2019 Iphone dev
35/42
Controller
@end
:
#import
@interface CalculatorViewController UIViewController
IBOutlet UILabel * display;
{
}
- (IBAction)digitPressed:(UIButton *)sender;
CalculatorBrain * brain;
- (IBAction)operationPressed:(UIButton *)sender;
ViewThese hook up to our
Wednesday, March 31, 2010
-
8/9/2019 Iphone dev
36/42
Controller
@end
:
#import
@interface CalculatorViewController UIViewController
IBOutlet UILabel * display;
{
}
- (IBAction)digitPressed:(UIButton *)sender;
CalculatorBrain * brain;
- (IBAction)operationPressed:(UIButton *)sender;
View
Model
Wednesday, March 31, 2010
-
8/9/2019 Iphone dev
37/42
CalculatorViewController.xib
Wednesday, March 31, 2010
-
8/9/2019 Iphone dev
38/42
Files Owner is our
Controller
CalculatorViewController.xib
Wednesday, March 31, 2010
-
8/9/2019 Iphone dev
39/42
Wednesday, March 31, 2010
-
8/9/2019 Iphone dev
40/42
Wednesday, March 31, 2010
-
8/9/2019 Iphone dev
41/42
Wednesday, March 31, 2010
-
8/9/2019 Iphone dev
42/42
top related