uikit

Swift- error: Variable 'self.___' used before being initialized

倾然丶 夕夏残阳落幕 提交于 2019-12-19 21:20:59
问题 I am trying to work with gesture recognizers in a Playground but am having some trouble. Here is my class: class foo { var fooVarSwipe: Any var fooVarTap: Any init() { let gr = UISwipeGestureRecognizer(target: self, action: #selector(foo.bar)) let tr = UITapGestureRecognizer(target: self, action: #selector(foo.tar)) helloApple.addGestureRecognizer(gr) helloApple.addGestureRecognizer(tr) helloApple.isUserInteractionEnabled = true self.fooVarSwipe = gr self.fooVarTap = tr } @objc func tar() {

Delegates vs. events in Cocoa Touch

你说的曾经没有我的故事 提交于 2019-12-19 19:28:57
问题 I'm writing my first iPhone app, and I've been exploring the design patterns in Cocoa Touch and Objective-C. I come from a background of client-side web development, so I'm trying to wrap my head around delegates. Specifically, I don't see why delegate objects are needed instead of event handlers. For instance, when the user presses a button, it is handled with an event ( UITouchUpInside ), but when the user finishes inputting to a text box and closes it with the 'Done' button, the action is

Determine frame/bounds in viewDidLoad

不想你离开。 提交于 2019-12-19 11:53:46
问题 Hello fellow programmers, First, sorry for the long post. My question is rather simple, but I want to make sure you know what I'm doing and I really don't want to change the basic idea of my approach. (the following is all done programmatically, no storyboards, no nibs, no navigationcontroller) I have a RootViewController without an own view. All he does is instantiate other ViewControllers, manage their transitions and push (add) their views into the main window. To position these views

How do you transition in a new non-model view controller without using UINavigationController?

独自空忆成欢 提交于 2019-12-19 10:58:36
问题 The following seems like a typical use case: You start the app with a LoginViewController that displays the login screen. Once the user has successfully logged in, you want to show the main view for your app (let's call it MainViewController). You don't want to put the LoginViewController into a UINavigationController and subsequently push MainViewController onto it because there's no reason to keep the LoginViewController present at the bottom of the stack since it will never be shown again.

iOS11 UISearchBar missing in UINavigationBar when embedded in UISplitViewController

喜你入骨 提交于 2019-12-19 10:57:33
问题 Strange things seem to happen when using the new iOS 11 navigationItem.searchController method on a detail view of a UISplitViewController . The searchBar partly appears as a blank space on the first presentation, then appears in the wrong UITableViewController , but corrects itself after a few push and pops of UITableViewController . I used to put the searchBar in the tableHeaderView , but I changed the code according to the WWDC recommendation: if (@available(iOS 11.0, *)) { self

UIKit and GCD thread-safety

杀马特。学长 韩版系。学妹 提交于 2019-12-19 10:29:17
问题 Many of the posts say that UIKit is totally not thread safe. Now on Apple documentation for GCD we can read that it's the DRAWING that is not thread safe. So would code like this be OK : dispatch_async( ^{ //do some work if(!self.window.rootViewController.presentedViewController && ) [self.window.rootViewController class] == anotherClass) { dispatch_async(dispatch_get_main_queue(), ^{ //do some work }); } }); 回答1: My personal opinion is that what you have heard so far is misleading. Here is a

Turn page programmatically in UIPageViewController when using UIPageViewControllerDataSource?

天涯浪子 提交于 2019-12-19 10:07:47
问题 I have an UIPageViewController and a class which conforms to UIPageViewControllerDataSource and manages the UIViewControllers which UIPageViewController displays. It all runs well when turning the pages is initiated by the user. But now I want to do that programmatically. I've found that there is a very similar question here on SO which answers the question for a static amount of ViewControllers: Is it possible to Turn page programmatically in UIPageViewController? But I'm unable to adapt the

How to NSLog pixel RGB from a UIImage?

烂漫一生 提交于 2019-12-19 09:38:32
问题 I just want to: 1) Copy the pixel data. 2) Iterate and Modify each pixel (just show me how to NSLog the ARGB values as 255) 3) Create a UIImage from the new pixel data I can figure out the the gory details if someone can just tell me how to NSLog the RGBA values of a pixel as 255. How do I modify the following code to do this? Be Specific Please! -(UIImage*)modifyPixels:(UIImage*)originalImage { NSData* pixelData = (NSData*)CGDataProviderCopyData(CGImageGetDataProvider(originalImage.CGImage))

Binding a UISwitch's state to a model with ReactiveCocoa

假如想象 提交于 2019-12-19 08:31:20
问题 I am trying to bind a UISwitch's on state to a boolean property in my model using ReactiveCocoa. I started with: RACChannelTo(self.switch, on, @NO) = RACChannelTo(self.model, toggle, @NO); This is how I've been binding other views to other parts of my model, unfortunately it didn't appear to do anything for the UISwitch. The model's state does not affect the switch, or vice versa. So I tried: RACChannelTo(self.model, toggle, @NO) = [self.switch rac_newOnChannel]; This appears to work ok, but

How to use scroll view on iPhone?

别说谁变了你拦得住时间么 提交于 2019-12-19 05:49:29
问题 I want to display a text with a lot of lines. I added a multiline-label to a scroll view, but it didn't show anything. Looks like this is not the correct way to use the scroll view. How to use scroll view so that users can drag down to see more text? 回答1: You can just use a UITextView. It's a child of UIScrollView, and if you set it's text property to an amount of text that does not fit within it's frame, the view will become scrollable. 回答2: Apple's UIScollView documentation is quite good,