viewcontroller

What is the method unarchiveFromFile in GameViewController for?

半城伤御伤魂 提交于 2019-12-10 09:29:53
问题 When I tried to add different scenes to my game in Swift, I encountered the method unarchiveFromFile. The problem with this method is that it only works with the GameScene class. If you call it from extension SKNode { class func unarchiveFromFile(file : NSString) -> SKNode? { if let path = NSBundle.mainBundle().pathForResource(file, ofType: "sks") { var sceneData = NSData.dataWithContentsOfFile(path, options: .DataReadingMappedIfSafe, error: nil) var archiver = NSKeyedUnarchiver

怎么优化ViewController,区分模块,分类管理

你离开我真会死。 提交于 2019-12-09 18:53:28
View controllers 通常是 iOS 项目中最大的文件,并且它们包含了许多不必要的代码。所以 View controllers 中的代码几乎总是复用率最低的。我们将会看到给 view controllers 瘦身的技术,让代码变得可以复用,以及把代码移动到更合适的地方。 你可以在 Github 上获取关于这个问题的 示例项目 。 把 Data Source 和其他 Protocols 分离出来 把 UITableViewDataSource 的代码提取出来放到一个单独的类中,是为 view controller 瘦身的强大技术之一。当你多做几次,你就能总结出一些模式,并且创建出可复用的类。 举个例,在示例项目中,有个 PhotosViewController 类,它有以下几个方法: # pragma mark Pragma- (Photo*)photoAtIndexPath:(NSIndexPath*)indexPath { return photos[(NSUInteger)indexPath.row]; } - (NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section { return photos.count; } - (UITableViewCell

How return a value from view2 to view1 when using navigation bar

≯℡__Kan透↙ 提交于 2019-12-09 13:25:06
问题 I am New to the iPhone Development. How can i carry a string value from view2 to view1 when using navigation bar. I have no problem in carrying string values from view1 to view2 to view3 to....by using pushviewcontroller But when i come back to previous views using Back button of navigation bar, I cannot able to hold string values. I need your help in solving this issue. Thanks In Advance 回答1: This thing can be done easily if the pass the reference of the current class to the next class and

How to create a confirmation Pop Up when pushing Back button in iOS?

霸气de小男生 提交于 2019-12-09 07:58:55
问题 I want to add a pop up when someone pushes the "Back" button of my iOS App, to ask the user if he really wants to come back. Then, depending on the user's response, I would like to undo the action or proceed. I've tried to add the code in the viewWillDisappear function of my view and then write the proper delegate but it doesn't work, because it always change the view and then show the pop up. My code is: -(void) viewWillDisappear:(BOOL)animated { _animated = animated; if ([self

iOS Dismiss and Present view controller custom animation

这一生的挚爱 提交于 2019-12-09 07:12:43
问题 I have a view controller that I am presenting with the following objective c code: CATransition *animation=[CATransition animation]; animation.delegate=self; animation.duration=0.3; animation.type=kCATransitionMoveIn; animation.subtype=kCATransitionFromRight; [self presentViewController:reader animated:NO completion:nil]; [reader.view.layer addAnimation:animation forKey:@"animation"]; and dismissing with similar code inside a delegate method CATransition *animation=[CATransition animation];

Understanding the use of addChildViewController

一个人想着一个人 提交于 2019-12-08 16:27:31
问题 I'm working with some code that I need to refactor. A view controller is acting as a container for two other view controllers, and will swap between them, as shown in the code below. This may not be the best design. Swapping the view controllers in this way might not be required. I understand that. However, as I work with this code I want to further understand what happens with the addChildViewController call. I haven't been able to find the answer in Apple's docs or in related questions,

Could not find a storyboard named 'Main' in bundle NSBundle?

大兔子大兔子 提交于 2019-12-08 13:29:13
问题 While trying to localize a SpriteKit game i suddenly started getting the error: "Could not find a storyboard named 'Main' in bundle NSBundle" I wasn't use a storyboard, and i think i actually deleted the file when i first started developing the game. 'Main storyboard file base name' was set to 'Main' (was set before as well when it worked and there was no storyboard). I deleted that entry and now the program just executes the AppDelegate file and essentially stops. What's missing where before

Calling methods between view controllers using Storyboard

不羁的心 提交于 2019-12-08 13:09:02
问题 I've already read the post Passing data to views using Storyboards, but still have problem with calling methods: Now I have AViewController and BViewController , both connected with Storyboard (no XIBs). In BViewController : -(void)doSth:(int)num; So how can I call the doSth: method in AViewController ? The old way like [bViewController doSth:123]; don't work because I can't get the instance of BViewController in the Storyboard. Thanks. Peak 回答1: I found if i use: MapViewController *mapView =

How do I segue an image to another ViewController and display it within an ImageView?

拥有回忆 提交于 2019-12-08 11:33:38
问题 The following code allows the user to select an image from the gallery or to take a picture and displays it within the ViewController via ImageView. What I want to do here is to pass the image that was taken or selected from the gallery and pass it to another ViewController to which it gets displayed in an ImageView. Ideally once the picture is selected or taken the ViewController changes immediately to the Second ViewController and displays the image in the ImageView. How can this be

Sliding-In UIView From Bottom

泄露秘密 提交于 2019-12-08 11:17:39
问题 I am trying to build a custom-looking action sheet. I thought the easiest way would be creating a view as a subview and assign constraint of subview's top to superview's bottom. And at the same time assigning a cover view with some opacity. Thus, I could have different versions of subview and I can initialise the necessary one and slide it. I couldn't find anything useful for Swift, so, using this obj-c answer, I tried to convert it to Swift. I achieved the opaque background with this however