cocoa-touch

Setting action for back button in navigation controller

浪子不回头ぞ 提交于 2019-12-29 08:32:49
问题 I'm trying to overwrite the default action of the back button in a navigation controller. I've provided a target an action on the custom button. The odd thing is when assigning it though the backbutton attribute it doesn't pay attention to them and it just pops the current view and goes back to the root: UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle: @"Servers" style:UIBarButtonItemStylePlain target:self action:@selector(home)]; self.navigationItem.backBarButtonItem =

Setting action for back button in navigation controller

两盒软妹~` 提交于 2019-12-29 08:32:31
问题 I'm trying to overwrite the default action of the back button in a navigation controller. I've provided a target an action on the custom button. The odd thing is when assigning it though the backbutton attribute it doesn't pay attention to them and it just pops the current view and goes back to the root: UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle: @"Servers" style:UIBarButtonItemStylePlain target:self action:@selector(home)]; self.navigationItem.backBarButtonItem =

checking for equality on dispatch_queue_t

和自甴很熟 提交于 2019-12-29 07:15:12
问题 How can I check for equality between dispatch_queue_t vars? dispatch_queue_t currentQueue = dispatch_get_current_queue(); dispatch_queue_t mainQueue = dispatch_get_main_queue(); if (currentQueue == mainQueue) { } from the docs: typedef struct dispatch_queue_s *dispatch_queue_t; I'm not sure but does this mean that it's a pointer to a dispatch_queue_s struct? Since I can't check equality on pointers, I'm not sure how can I check if a dispatch_queue_t is the same as another? 回答1: This depends

The final word on NSStrings: Mutable and Immutable

随声附和 提交于 2019-12-29 06:19:02
问题 I've read in several books... and online... about immutable and mutable strings. They claim "immutable strings" can't be changed. (But they never define "change".) Which of these NSStrings could be changed without using NSMutableString? The string contains "catfish"... and I later try to change it to "cat". (Same letters, just shorter.) It contains "cat"... and I try to change it to "catfish". (Similar start... but just made longer.) I change "cat" into "CAT". (Same letters, but just the case

Is it a bad practice to use your AppDelegate as your Singleton?

这一生的挚爱 提交于 2019-12-29 06:11:58
问题 I'm sometimes using a Singleton (to store data that is used by several different classes) in my projects and I'm thinking why not use my AppDeletage, since it's already a Singleton and easy to access. Is this a bad practice and if so, why? 回答1: There is no right answer to this one. You'll get many opinions on this. I see no issue with using the AppDelegate, and I do it for all my apps: The delegate is practically mandatory for iPhone apps, it's there for the lifetime of the app; and one can

Is it a bad practice to use your AppDelegate as your Singleton?

假装没事ソ 提交于 2019-12-29 06:10:28
问题 I'm sometimes using a Singleton (to store data that is used by several different classes) in my projects and I'm thinking why not use my AppDeletage, since it's already a Singleton and easy to access. Is this a bad practice and if so, why? 回答1: There is no right answer to this one. You'll get many opinions on this. I see no issue with using the AppDelegate, and I do it for all my apps: The delegate is practically mandatory for iPhone apps, it's there for the lifetime of the app; and one can

Actual frequency of device motion updates lower than expected, but scales up with setting

こ雲淡風輕ζ 提交于 2019-12-29 05:58:09
问题 I am porting an app that I originally wrote using the accelerometer for IOS 3, to incorporate the new IOS 4 motion capabilities. While capturing motion, the application does little else - no graphics updates for example. I'm doing the following to set up motion updates, as a replacement for my previous use of the accelerometer. I do realize that I could rebuild to do my own polling using NSTimer or something, and may pursue that yet. [motionManager setDeviceMotionUpdateInterval:updateInterval

How do I get the name of a day of the week in the user's locale?

跟風遠走 提交于 2019-12-29 05:47:27
问题 I have a number between 1 and 7, which I want to turn into the user's locale's equivalent of Monday to Sunday. Can I do that and if so, how? 回答1: An NSDateFormatter can give you the list of names: NSDateFormatter * df = [[NSDateFormatter alloc] init]; [df setLocale: [NSLocale currentLocale]]; NSArray * weekdays = [df weekdaySymbols]; Which you can then index like any other array [weekdays objectAtIndex:dayIdx]; Be aware, however, that the first weekday may differ by locale; exactly how it may

iOS 9 supportedInterfaceOrientations not working

百般思念 提交于 2019-12-29 05:47:10
问题 I have a UIViewController with the following code: - (BOOL) shouldAutorotate { return NO; } -(NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationPortrait; } I am not using a UINavigationController . When this UIViewController is being displayed, the device will still rotate to landscape. I am targeting iOS 9, what's the issue here? 回答1: So the issue was that I had defined the allowed orientations in info.plist which apparently overrides anything you do anywhere else

NSHTTPCookies refuse to be deleted

痞子三分冷 提交于 2019-12-29 05:27:07
问题 I need a log out button for my app, I have the below code: while ([[[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies] count] != 0) { for (NSHTTPCookie *cookie in [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies]) { [[NSHTTPCookieStorage sharedHTTPCookieStorage] deleteCookie:cookie]; } } (the while is just there to make sure they get deleted, it only runs once however) If I NSLog the description of shared cookie storage after the above code it outputs that the array is empty.