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

  • Published on
    29-Nov-2014

  • View
    2.048

  • Download
    1

Embed Size (px)

DESCRIPTION

 

Transcript

<ul><li> 1. iOS 2MVC,View, Controllers </li> <li> 2. ?http://stackoverow.com/questions/411048/differences-between-private-elds-and-private-properties </li> <li> 3. </li> <li> 4. ? </li> <li> 5. ? , </li> <li> 6. ? , Objective-C? </li> <li> 7. ? , Objective-C? </li> <li> 8. "string1" @"string2" </li> <li> 9. "string1" @"string2"Char* NSString* </li> <li> 10. 5 ? </li> <li> 11. 5 ? NSNumber </li> <li> 12. strong weak? ? </li> <li> 13. strong weak? ? , strong , weak </li> <li> 14. - (void)deleteProfile; </li> <li> 15. - (void)deleteProfile; </li> <li> 16. ?@property(nonatomic) NSInteger age; </li> <li> 17. ? @property(nonatomic) NSInteger age;getter, setter, </li> <li> 18. ? User *user = ... </li> <li> 19. ? User *user = ...User *user = [[User alloc] init]; </li> <li> 20. Objective-C? </li> <li> 21. Objective-C? NSObject </li> <li> 22. user topic, text- (void)postCommentWithTopic:(NSString *)topic andText:(NSString *)text; </li> <li> 23. user topic, text- (void)postCommentWithTopic:(NSString *)topic andText:(NSString *)text;[user postCommentWithTopic:@"topic"andText:@"text"]; </li> <li> 24. MVC ControllerView Model </li> <li> 25. View </li> <li> 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; </li> <li> 27. UIView </li> <li> 28. </li> <li> 29. Controller </li> <li> 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); </li> <li> 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 </li> <li> 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];} </li> <li> 33. Interface Builder () </li> <li> 34. </li> <li> 35. target, action- (void)viewDidLoad{ [super viewDidLoad]; [self.button addTarget:self action:@selector(buttonClicked) forControlEvents:UIControlEventTouchUpInside];}- (void)buttonClicked{ NSLog(@"buttonClicked");} </li> <li> 36. delegate@interface ViewController : UIViewController- (void)viewDidLoad{ [super viewDidLoad]; self.tableView.delegate = self;}- (void)tableView:(UITableView *)tableViewdidSelectRowAtIndexPath:(NSIndexPath *)indexPath{ NSLog(@"select row");} </li> <li> 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;... </li> <li> 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(@" ");} </li> <li> 39. MVC ControllerView Model </li> <li> 40. MVC Controller outletsView Model </li> <li> 41. MVC Controller outletsView Model </li> <li> 42. MVC Controller delegates outletsView Model </li> <li> 43. MVC Controller delegatestarget,action outlets View Model </li> <li> 44. MVC Controller delegatestarget,action outlets View Model </li> <li> 45. MVC Controller delegatestarget,action notications outlets View Model </li> <li> 46. </li> <li> 47. ? </li> <li> 48. ? </li> <li> 49. ? UIView </li> <li> 50. ? </li> <li> 51. ? UIViewController </li> <li> 52. view Interface Builder? </li> <li> 53. view Interface Builder? IBOutlet </li> <li> 54. ? </li> <li> 55. ? notication- </li> <li> 56. view ? </li> <li> 57. view ? target/action delegate </li> <li> 58. - UIWebView (, : , /) </li> <li> 59. - UIScrollView (, ) </li> <li> 60. - MKMapView (, ) </li> <li> 61. - UITableView (, ) </li> <li> 62. gleb34@gmail.com twitter.com/pilot34 </li> </ul>