cocoa-touch

Convert an NSDate to a Unix timestamp using a particular time zone

前提是你 提交于 2020-01-23 01:43:13
问题 I am trying to get the Unix timestamp using a particular time zone (not necessarily the same time zone as the system) I tried this : NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; NSTimeZone *gmt = [NSTimeZone timeZoneWithName:@"Australia/Melbourne"]; [dateFormatter setTimeZone:gmt]; NSString *timeStamp = [dateFormatter stringFromDate:[NSDate date]]; NSDate *curdate = [dateFormatter dateFromString:timeStamp]

blocks in nsdictionary?

回眸只為那壹抹淺笑 提交于 2020-01-22 23:11:25
问题 So I'm storing block actions into a nsmutabledictionary and then recalling them when a response comes back on a websocket. This turns async request into a block syntax. Here's the stripped down code: - (void)sendMessage:(NSString*)message responseAction:(void (^)(id))responseAction { NSString *correlationID = (NSString*)[[message JSONValue] objectForKey:@"correlationId"]; [self.messageBlocks setObject:responseAction forKey:correlationID]; NSLog(@"Sending message: %@", correlationID);

blocks in nsdictionary?

我们两清 提交于 2020-01-22 23:07:41
问题 So I'm storing block actions into a nsmutabledictionary and then recalling them when a response comes back on a websocket. This turns async request into a block syntax. Here's the stripped down code: - (void)sendMessage:(NSString*)message responseAction:(void (^)(id))responseAction { NSString *correlationID = (NSString*)[[message JSONValue] objectForKey:@"correlationId"]; [self.messageBlocks setObject:responseAction forKey:correlationID]; NSLog(@"Sending message: %@", correlationID);

Is there a way to set a separate short title for UITabBar?

送分小仙女□ 提交于 2020-01-22 22:56:56
问题 I'd like to be able to give my views short names for display on the tab bar, and longer (more descriptive) name when the same view is linked to in a table view. The reason is that longer names nudge up against each other on the tab bar. In a table view, there's more horizontal space, so I want to use more descriptive titles there. Normally, the tab bar's title is set in its view controller with self.title . Is there a way to specifically set the tab bar title, but leave the view controller's

UIViewController.View.Window is null in ViewDidLoad method

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-22 17:20:54
问题 Regardless on which controller type ( UIViewController , UITableViewController ), the following line always yields null in the ViewDidLoad method: this.View.Window Is this behavior normal, or am I doing something odd? What could lead to UIViewController.View.Window being null ? (I suppose this question concerns not only MonoTouch, but also 'normal' Objective-C Cocoa). (MonoTouch 5.2.11, XCode 4.2.1 4D502) 回答1: According to the documentation of UIView, the window property is nil if the view

NSCache auto-removal policy

本小妞迷上赌 提交于 2020-01-22 14:31:30
问题 What are some of the NSCache's auto-removal policies? Apple's documentation does not mention them, and I experimentally discovered that NSCache does not respond to memory warning. 回答1: You're best off treating NSCache as a black box, as much as you can. From Caching and Purgeable Memory (emphasis mine): When adding items to a cache, you can specify a cost value to be associated with each key-value pair. Call the setTotalCostLimit: method to set the maximum value for the sum of all the cached

NSCache auto-removal policy

拜拜、爱过 提交于 2020-01-22 14:29:45
问题 What are some of the NSCache's auto-removal policies? Apple's documentation does not mention them, and I experimentally discovered that NSCache does not respond to memory warning. 回答1: You're best off treating NSCache as a black box, as much as you can. From Caching and Purgeable Memory (emphasis mine): When adding items to a cache, you can specify a cost value to be associated with each key-value pair. Call the setTotalCostLimit: method to set the maximum value for the sum of all the cached

NSCache auto-removal policy

前提是你 提交于 2020-01-22 14:29:04
问题 What are some of the NSCache's auto-removal policies? Apple's documentation does not mention them, and I experimentally discovered that NSCache does not respond to memory warning. 回答1: You're best off treating NSCache as a black box, as much as you can. From Caching and Purgeable Memory (emphasis mine): When adding items to a cache, you can specify a cost value to be associated with each key-value pair. Call the setTotalCostLimit: method to set the maximum value for the sum of all the cached

How to determine if the user has scrolled to the bottom of the UITableView?

我的未来我决定 提交于 2020-01-22 13:58:06
问题 How can I determine if the user has scrolled to the last cell/bottom of a UITableView? 回答1: UITableView inherits from UIScrollView, and scroll view exposes a contentOffset property (documentation here). Use this with a bit of math to determine if the contentOffset is within frame.size.height of the bottom. Update: here's a stab at a formula that will give you what you want: if(tableView.contentOffset.y >= (tableView.contentSize.height - tableView.frame.size.height)) { //user has scrolled to

Cocoa Threadsafe Mutable Collection Access

Deadly 提交于 2020-01-22 13:12:52
问题 I'm creating a KVC/KVO-compliant mutable array on one of my objects the recommended way: @interface Factory { NSMutableArray *widgets; } - (NSArray *)widgets; - (void)insertObject:(id)obj inWidgetsAtIndex:(NSUInteger)idx; - (void)removeObjectFromWidgetsAtIndex:(NSUInteger)idx; @end Clearly this is a tricky thread-safety issue. In the insert and remove methods I'm locking around array access to prevent concurrent modification, as recommended. My question is, what is the proper way to implement