// In Swift should check the method, even user don't tap the cantainer view. // But in Objective-C, *** Terminating app due to uncaught exception 'NSInvalidUnarchiveOperationException', // reason: 'Could not instantiate class named AVPlayerViewController' - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // set up the player if ([segue.identifier isEqual: @"videoSegue"]) { NSString *path = [[NSBundle mainBundle] pathForResource:@"yishengsuoai" ofType:@"mp4"]; NSURL *url = [[NSURL alloc] initFileURLWithPath:path]; AVPlayerViewController *vc = segue.destinationViewController; vc.player = [AVPlayer playerWithURL:url]; }
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14
// BEGIN avkit_ios_config overridefuncprepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { if segue.identifier =="videoSegue" { // set up the player let videoURL =NSBundle.mainBundle().URLForResource("TestVideo", withExtension: "m4v") let videoViewController = segue.destinationViewController as!AVPlayerViewController videoViewController.player =AVPlayer(URL: videoURL) } } // END avkit_ios_config
2. Conclusion
Swift + Container View(In IB)
Objective-C + AVPlayerLayer (In Code)
3. Definiton
- prepareForSegue:sender:
Notifies the view controller that a segue is about to be performed.
###Discussion
The default implementation of this method does nothing. Your view controller overrides this method when it needs to pass relevant data to the new view controller. The segue object describes the transition and includes references to both view controllers involved in the segue.
Because segues can be triggered from multiple sources, you can use the information in the segue and sender parameters to disambiguate between different logical paths in your app. For example, if the segue originated from a table view, the sender parameter would identify the table view cell that the user tapped. You could use that information to set the data on the destination view controller.
// "Delete" the extra separator of UITableView and the last one Separator in ecah Section - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { return0.01f; }
// Updating Objects with primary keys // This will make properties no settled be NULL [GWClassmate createOrUpdateInDefaultRealmWithValue:newClassmate];
- (BOOL)canBecomeFirstResponder; // default is NO - (BOOL)becomeFirstResponder;
- (BOOL)canResignFirstResponder; // default is YES - (BOOL)resignFirstResponder;
- (BOOL)isFirstResponder;
// Generally, all responders which do custom touch handling should override all four of these methods. // Your responder will receive either touchesEnded:withEvent: or touchesCancelled:withEvent: for each // touch it is handling (those touches it received in touchesBegan:withEvent:). // *** You must handle cancelled touches to ensure correct behavior in your application. Failure to // do so is very likely to lead to incorrect behavior or crashes. - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event; - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event; - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event; - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event;
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender NS_AVAILABLE_IOS(3_0); // Allows an action to be forwarded to another target. By default checks -canPerformAction:withSender: to either return self, or go up the responder chain. - (id)targetForAction:(SEL)action withSender:(id)sender NS_AVAILABLE_IOS(7_0);
Model 是不可变的,所以我们可以只在初始化的时候指定我们 View Model 的属性。对于可变 Model,我们还需要使用一些绑定机制,这样 View Model 就能在背后的 Model 改变时更新自身的属性。此外,一旦 View Model 上的 Model 发生改变,那 View 的属性也需要更新。Model 的改变应该级联向下通过 View Model 进入 View。
I will often create a singleton manager class that handles setting up the Core Data stack, and deals with all of the fetching/saving that is involved with the stack. As the quote you mentioned says, this makes it very easy to not only call those methods, but to adjust them if needed, as opposed to having saving/fetching calls all over the place in different view controllers.
AFNetworkReachabilityManager monitors the reachability of domains, and addresses for both WWAN and WiFi network interfaces.
Do not use Reachability to determine if the original request should be sent.
You should try to send it. You can use Reachability to determine when a request should be automatically retried. Although it may still fail, a Reachability notification that the connectivity is available is a good time to retry something. Network reachability is a useful tool for determining why a request might have failed. After a network request has failed, telling the user they’re offline is better than giving them a more technical but accurate error, such as “request timed out.”
AFNetworking takes advantage of Foundation URL Loading System caching using NSURLCache, as well as a configurable in-memory cache for UIImageView and UIButton, which uses NSCache by default. Caching behavior can be further specified in the caching policy of a corresponding NSURLRequest. Other SDWebImage features, like background decompression of image data is also provided by AFNetworking.
If you’re already using AFNetworking and just want an easy async image loading category, the built-in UIKit extensions will probably fit your needs.