cocoa-touch

Simple http post example in Objective-C?

帅比萌擦擦* 提交于 2019-12-27 16:25:57
问题 I have a php webpage that requires a login (userid & password). I have the user enter the information into the app just fine.. but I need an example on how to do a POST request to a website. The apple example on the support site is rather complicated showing a picture upload.. mine should be simpler.. I just want to post 2 lines of text.. Anyone have any good examples? Alex 回答1: This is what I recently used, and it worked fine for me: NSString *post = @"key1=val1&key2=val2"; NSData *postData

How do I auto size a UIScrollView to fit its content

情到浓时终转凉″ 提交于 2019-12-27 12:09:19
问题 Is there a way to make a UIScrollView auto-adjust to the height (or width) of the content it's scrolling? Something like: [scrollView setContentSize:(CGSizeMake(320, content.height))]; 回答1: The best method I've ever come across to update the content size of a UIScrollView based on its contained subviews: Objective-C CGRect contentRect = CGRectZero; for (UIView *view in self.scrollView.subviews) { contentRect = CGRectUnion(contentRect, view.frame); } self.scrollView.contentSize = contentRect

What's the best way to find the user's Documents directory on an iPhone?

和自甴很熟 提交于 2019-12-27 11:55:43
问题 I'm reading Erica Sadun's iPhone Developer's Cookbook , and ran into a question. She says in the book that the way to find the user's Documents directory is with the code: [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]; but that seems slightly brittle, and dissimiliar to the normal Mac way of doing it, which would be: NSSearchPathForDirectoriesInDomains(NSDocumentsDirectory, NSUserDomainMask, YES); Are there any particular reasons to use one over the other? 回答1: Objc: NSArray

How do I scroll the UIScrollView when the keyboard appears?

半城伤御伤魂 提交于 2019-12-27 11:49:58
问题 I'm having trouble with my code. I'm trying to move the UIScrollView when I'm editing an UITextField that should be hidden by the keyboard pop. I'm moving the main frame right now because I don't know how to 'scroll up' in the code. So, I did a little bit of code, it's working fine but when I edit an UItextfield and I switch to another UITextField without pressing on the 'return' button the main view goes waaayyyyy to far up. I did an NSLog() with my variables size, distance and textFieldRect

Blank space at top of UITextView in iOS 10

邮差的信 提交于 2019-12-27 11:00:39
问题 I have UITextView with some text in it. Everything was fine with iOS 6 but now with iOS 7 it leaves the blank space on top and then place the text below the middle of the textview. I didn't set any contentOffSet. Please Help! 回答1: A text view is a scroll view. View controllers will add a content offset automatically to scroll views, as it is assumed they will want to scroll up behind the nav bar and status bar. To prevent this, set the following property on the view controller containing the

iCloud basics and code sample [closed]

送分小仙女□ 提交于 2019-12-27 10:57:07
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 8 years ago . As a beginner, I'm struggling with iCloud. There are some samples, but they are usually quite detailed (on the developer forum there

UIBarButtonItem with color?

对着背影说爱祢 提交于 2019-12-27 10:42:48
问题 Is it possible to have a red UIBarButtonItem? 回答1: If anyone is looking for code to exactly duplicate a simple UIBarButtonItem: UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; [button setBackgroundImage:[UIImage imageNamed:@"delete.png"] forState:UIControlStateNormal]; [button setTitle:@"Delete" forState:UIControlStateNormal]; button.titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:12.0f]; [button.layer setCornerRadius:4.0f]; [button.layer setMasksToBounds:YES];

Getting a list of files in a directory with a glob

烈酒焚心 提交于 2019-12-27 10:30:55
问题 For some crazy reason I can't find a way to get a list of files with a glob for a given directory. I'm currently stuck with something along the lines of: NSString *bundleRoot = [[NSBundle mainBundle] bundlePath]; NSArray *dirContents = [[NSFileManager defaultManager] directoryContentsAtPath:bundleRoot]; ..and then stripping out the stuff I don't want, which sucks. But what I'd really like is to be able to search for something like "foo*.jpg" instead of asking for the entire directory, but I

Zooming MKMapView to fit annotation pins?

南笙酒味 提交于 2019-12-27 10:29:07
问题 I am using MKMapView and have added a number of annotation pins to the map about a 5-10 kilometre area. When I run the application my map starts zoomed out to show the whole world, what is the best way to zoom the map so the pins fit the view? EDIT: My initial thinking would be to use MKCoordinateRegionMake and calculate the coordinate centre, longitudeDelta and latitudeDelta from my annotations. I am pretty sure this will work, but I just wanted to check I was not missing anything obvious.

How to determine the content size of a UIWebView?

大城市里の小女人 提交于 2019-12-27 09:02:12
问题 I have a UIWebView with different (single page) content. I'd like to find out the CGSize of the content to resize my parent views appropriately. The obvious -sizeThatFits: unfortunately just returns the current frame size of the webView. 回答1: It turned out that my first guess using -sizeThatFits: was not completely wrong. It seems to work, but only if the frame of the webView is set to a minimal size prior to sending -sizeThatFits: . After that we can correct the wrong frame size by the