Школа-студия разработки приложений для iOS. 2 лекция. MVC, View, Controllers

  • Published on
    29-Nov-2014

  • View
    2.047

  • Download
    1

Embed Size (px)

DESCRIPTION

 

Transcript

  • 1. iOS 2MVC,View, Controllers
  • 2. ?http://stackoverow.com/questions/411048/differences-between-private-elds-and-private-properties
  • 3.
  • 4. ?
  • 5. ? ,
  • 6. ? , Objective-C?
  • 7. ? , Objective-C?
  • 8. "string1" @"string2"
  • 9. "string1" @"string2"Char* NSString*
  • 10. 5 ?
  • 11. 5 ? NSNumber
  • 12. strong weak? ?
  • 13. strong weak? ? , strong , weak
  • 14. - (void)deleteProfile;
  • 15. - (void)deleteProfile;
  • 16. ?@property(nonatomic) NSInteger age;
  • 17. ? @property(nonatomic) NSInteger age;getter, setter,
  • 18. ? User *user = ...
  • 19. ? User *user = ...User *user = [[User alloc] init];
  • 20. Objective-C?
  • 21. Objective-C? NSObject
  • 22. user topic, text- (void)postCommentWithTopic:(NSString *)topic andText:(NSString *)text;
  • 23. user topic, text- (void)postCommentWithTopic:(NSString *)topic andText:(NSString *)text;[user postCommentWithTopic:@"topic"andText:@"text"];
  • 24. MVC ControllerView Model
  • 25. View
  • 26. UIView@property(nonatomic) CGRect frame;@property(nonatomic) CGRect bounds;@property(nonatomic) CGPoint center;@property(nonatomic,readonly) UIView *superview;@property(nonatomic,readonly,copy) NSArray *subviews;- (void)removeFromSuperview;- (void)addSubview:(UIView *)view;- (void)bringSubviewToFront:(UIView *)view;- (void)sendSubviewToBack:(UIView *)view;@property(nonatomic,copy) UIColor *backgroundColor;@property(nonatomic) CGFloat alpha;@property(nonatomic,getter=isHidden) BOOL hidden;
  • 27. UIView
  • 28.
  • 29. Controller
  • 30. UIViewController// The getter first invokes [self loadView] if the view hasnt been set yet.// Subclasses must call super if they override the setter or getter.@property(nonatomic,retain) UIView *view;// This is where subclasses should create their custom view hierarchy// if they arent using a nib.// Should never be called directly.- (void)loadView;- (void)viewWillUnload __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_5_0);// Called after the view has been loaded. For view controllers created incode,// this is after -loadView. For view controllers unarchived from a nib,// this is after the view is set.- (void)viewDidLoad;// Called after the view controllers view is released and set to nil.// For example, a memory warning which causes the view to be purged.// Not invoked as a result of -dealloc.- (void)viewDidUnload __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0);- (BOOL)isViewLoaded __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0);
  • 31. @interface ViewController : UIViewController@end@implementation ViewController- (void)viewDidLoad{ [super viewDidLoad]; CGRect rect = CGRectMake(20, 20, 100, 100); UILabel *l = [[UILabel alloc] initWithFrame:rect]; l.text = @"text"; [self.view addSubview:l];}- (void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; NSLog(@"");}- (void)viewWillDisappear:(BOOL)animated{ [super viewWillDisappear:animated]; NSLog(@"");}@end
  • 32. View Interface Builder- (void)viewDidLoad{ [super viewDidLoad]; CGRect rect = CGRectMake(20, 20, 100, 100); UILabel *l = [[UILabel alloc] initWithFrame:rect]; l.text = @"text"; [self.view addSubview:l];}
  • 33. Interface Builder ()
  • 34.
  • 35. target, action- (void)viewDidLoad{ [super viewDidLoad]; [self.button addTarget:self action:@selector(buttonClicked) forControlEvents:UIControlEventTouchUpInside];}- (void)buttonClicked{ NSLog(@"buttonClicked");}
  • 36. delegate@interface ViewController : UIViewController- (void)viewDidLoad{ [super viewDidLoad]; self.tableView.delegate = self;}- (void)tableView:(UITableView *)tableViewdidSelectRowAtIndexPath:(NSIndexPath *)indexPath{ NSLog(@"select row");}
  • 37. UIScrollViewDelegate@protocol UIScrollViewDelegate@optional// any offset changes- (void)scrollViewDidScroll:(UIScrollView *)scrollView;// any zoom scale changes- (void)scrollViewDidZoom:(UIScrollView *)scrollView__OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_2);// called on start of dragging// (may require some time and or distance to move)- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView;...
  • 38. notications :NSNotificationCenter *center = [NSNotificationCenter defaultCenter];[center postNotificationName:@"UserChanged" object:nil]; :NSNotificationCenter *center = [NSNotificationCenter defaultCenter];[center addObserver:self selector:@selector(userChanged) name:@"UserChanged" object:nil];- (void)userChanged{ NSLog(@" ");}
  • 39. MVC ControllerView Model
  • 40. MVC Controller outletsView Model
  • 41. MVC Controller outletsView Model
  • 42. MVC Controller delegates outletsView Model
  • 43. MVC Controller delegatestarget,action outlets View Model
  • 44. MVC Controller delegatestarget,action outlets View Model
  • 45. MVC Controller delegatestarget,action notications outlets View Model
  • 46.
  • 47. ?
  • 48. ?
  • 49. ? UIView
  • 50. ?
  • 51. ? UIViewController
  • 52. view Interface Builder?
  • 53. view Interface Builder? IBOutlet
  • 54. ?
  • 55. ? notication-
  • 56. view ?
  • 57. view ? target/action delegate
  • 58. - UIWebView (, : , /)
  • 59. - UIScrollView (, )
  • 60. - MKMapView (, )
  • 61. - UITableView (, )
  • 62. gleb34@gmail.com twitter.com/pilot34

Recommended

View more >