CS175
Chris Pollett
Sep 10, 2014
// // MFAViewController.h // MyButtonApp // // Created by Chris Pollett on 9/10/14. // Copyright (c) 2014 Chris Pollett. All rights reserved. // #import <UIKit/UIKit.h> @interface MFAViewController : UIViewController @end
// // MFAViewController.m // MyButtonApp // // Created by Chris Pollett on 9/10/14. // Copyright (c) 2014 Chris Pollett. All rights reserved. // #import "MFAViewController.h" @interface MFAViewController () @end @implementation MFAViewController @end
#import <UIKit/UIKit.h> @interface MFAViewController : UIViewController @property (weak, nonatomic) IBOutlet UILabel *statusLabel; -(IBAction)buttonPressed:(UIButton *)sender; @end
#ifndef IBOutlet #define IBOutlet #endif
UILabel *tmp = myController.statusText; myController.statusText = someLabel;
-(IBAction) actionMethod; -(IBAction) actionMethod:(id)sender; -(IBAction) actionMethod:(id)sender withEvent:(UIEvent *)event;
// // MFAViewController.m // MyButtonApp // // Created by Chris Pollett on 9/10/14. // Copyright (c) 2014 Chris Pollett. All rights reserved. // #import "MFAViewController.h" @interface MFAViewController () @end @implementation MFAViewController -(IBAction)buttonPressed:(UIButton *)sender { NSString *title = [sender titleForState:(UIControlState)UIControlStateNormal]; NSString *newText = [NSString stringWithFormat:@"%@ button pressed.",title]; _statusLabel.text = newText; } @end
UIImage *bob = [UIImage imageNamed:@"bob.png"];
// // MFAAppDelegate.h // MyButtonApp // // Created by Chris Pollett on 9/10/14. // Copyright (c) 2014 Chris Pollett. All rights reserved. // #import <UIKit/UIKit.h> @interface MFAAppDelegate : UIResponder <UIApplicationDelegate> @property (strong, nonatomic) UIWindow *window; @end
#import "MFAAppDelegate.h" @implementation MFAAppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. return YES; } - (void)applicationWillResignActive:(UIApplication *)application { // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. } - (void)applicationDidEnterBackground:(UIApplication *)application { // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. } - (void)applicationWillEnterForeground:(UIApplication *)application { // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. } - (void)applicationDidBecomeActive:(UIApplication *)application { // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. } - (void)applicationWillTerminate:(UIApplication *)application { // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. } @end
@autoreleasepool { return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); }
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; int retVal = UIApplicationMain(argc, argv, nil, nil); [pool release];
@interface MyButtonAppDelegate : UIResponder <UIApplicationDelegate>says we are extending NSObject and implementing the UIApplicationDelegate protocol.
@protocol MyInterface -(void) myMethod; @end;
@interface AClass -(void) aMethod; @endAssume this was implemented in some implementation .m file we don't have access to...
#import "AClass.h" @interface AClass (MyMods) -(void) niftyMethod; @endand implement it in MyModsAClass.m:
@implement AClass (MyMods) -(void) niftyMethod { // some code } @end
#import "AClass.h" #import "MyModsAClass.m" int main( int argc, const char *argv[] ) { AClass *aClass = [[AClass alloc] init]; //uses AClass(MyMods) .... }
@interface AClass -(void) aMethod; @end
#import "AClass.h" @interface AClass (Private) -(void) niftyMethod; @end @implement AClass -(void) aMethod { //some code, could call nifty Method } @end @implement AClass (Private) -(void) niftyMethod { // some code } @end
#import "AClass.h" int main( int argc, const char *argv[] ) { AClass *aClass = [[AClass alloc] init]; // could not call [aClass niftyMethod]; }