cocoa-touch

How to avoid nested blocks

只愿长相守 提交于 2020-01-16 06:41:03
问题 GCD and blocks are so nice and convenient. But when I fall in love with it, I found that something bad happened. Look at these codes below: [self functionA:^(BOOL success) { if (success) { dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void) { [self functionB:^(NSError *error) { if (error != nil) { dispatch_async(dispatch_get_main_queue(), ^(void) { [self functionC:^(id result) { if (result) { [self functionD:^(BOOL success) { if (success) { [self DoSomething]

How to avoid nested blocks

雨燕双飞 提交于 2020-01-16 06:39:32
问题 GCD and blocks are so nice and convenient. But when I fall in love with it, I found that something bad happened. Look at these codes below: [self functionA:^(BOOL success) { if (success) { dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void) { [self functionB:^(NSError *error) { if (error != nil) { dispatch_async(dispatch_get_main_queue(), ^(void) { [self functionC:^(id result) { if (result) { [self functionD:^(BOOL success) { if (success) { [self DoSomething]

Cocoa touch/Xcode - generating NIB-less graphics context

大城市里の小女人 提交于 2020-01-16 05:15:10
问题 My app delegate contains: - (void)applicationDidFinishLaunching:(UIApplication *)application { // Override point for customization after app launch window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; if (!window) { [self release]; return; } window.backgroundColor = [UIColor greenColor]; [window addSubview:viewController.view]; [window makeKeyAndVisible]; [window layoutSubviews]; } This does get executed, apparently with no errors. The window variable is NOT 0 so the test

cocoa touch NSDateFormatter and epoch date

匆匆过客 提交于 2020-01-16 02:55:06
问题 I have a string that is (I think) an epoch date. Here is the example string: 1372620996 Heres part of the code: NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; NSDate *offerDate = [dateFormatter dateFromString:@"1372620996"]; This returns a null date, and I'm pretty sure my problem is because I haven't set a dateStyle on my NSDateFormatter. However, I'm not sure what dateStyle to use for an epoch date. 回答1: It's actually simpler than that to convert to an NSDate; NSString

How do I do this NSPredicate code?

限于喜欢 提交于 2020-01-16 00:56:08
问题 I'm having trouble with NSPredicate. I have a core data object called Entry, which contains an NSDate called creationDate. I want to compare this to the variable I have called date. I'm using an NSDate category to pull out the individual year of both objects, and a core data category to perform a predicate on all Entry objects in my core data store. [Entry allForPredicate:[NSPredicate predicateWithFormat:@"creationDate.year == %i", date.year]]; I think this is wrong, as it's not giving me the

Animate to a storyboard state / position

亡梦爱人 提交于 2020-01-16 00:44:09
问题 I've got a view controller in Storyboard that has a bunch of images, labels and buttons correctly positioned for how the view is supposed to look after initial animations. Is there a simple way to save the original position of each and every element (that is to say the position that they're in on the Storyboard) on init so that it's possible to take those elements, move them out of view and animate them to the Storyboard layout / positions? 回答1: Yes this can be done by saving all the view's

UITableView setEditing to NO doesn't change barButtonItem back

烂漫一生 提交于 2020-01-16 00:41:13
问题 I have a UITableViewController inside of a UINavigationController . I am setting the rightBarButtonItem to the editing button: self.navigationItem.rightBarButtonItem = self.editButtonItem; This works great, and after I call tableView:commitEditingStyle:forRowAtIndexPath: I programmatically change my tableView out of editing mode using: [self.tableView setEditing:NO animated:YES]; The strange thing here is, the barButtonItem still seems to be in "edit mode" as it still says "Done" like it does

Disabling the 'Search' button in the searchbar keyboard [duplicate]

房东的猫 提交于 2020-01-15 23:38:21
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: How can I disable/enable UISearchBar keyboard's Search button? Can we disable the 'Search' button in the keyboard for a search bar? I want to enable it after user enters 3 characters in the search bar. 回答1: Apparently, you can't do that. You need to implement UISearchBar's delegate - searchBarSearchButtonClicked: You can just add a condition in your delegate like: - (void)searchBarSearchButtonClicked:

Disabling the 'Search' button in the searchbar keyboard [duplicate]

左心房为你撑大大i 提交于 2020-01-15 23:36:48
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: How can I disable/enable UISearchBar keyboard's Search button? Can we disable the 'Search' button in the keyboard for a search bar? I want to enable it after user enters 3 characters in the search bar. 回答1: Apparently, you can't do that. You need to implement UISearchBar's delegate - searchBarSearchButtonClicked: You can just add a condition in your delegate like: - (void)searchBarSearchButtonClicked:

Is there any way to access iPhone mail app mailboxes inside my own iphone app?

孤人 提交于 2020-01-15 23:01:25
问题 I wonder if there's any way to loop inside a mailbox and get the list of messages inside the mailbox. I want to open each message and take screen shot of the email. Is there any way to do this? Any reference? Thanks for your help. 回答1: AFAIK there is not. The only mail interface comes from the MFMailComposeViewController . 回答2: I hope not. 回答3: Ask the user for their credentials, and access it via standard POP3/IMAP. If your use is legitimate, they'll be more than happy to enter them. Apple