ios4

Hide keyboard in applicationDidEnterBackground: - screenshot problem

筅森魡賤 提交于 2020-01-02 08:31:14
问题 When the home button gets pressed I want to hide the keyboard and restore my view to a sane state, so that when the app is started/foregrounded again, there is no textfield selected and the keyboard is hidden. My app delegate has this implementation of the method: - (void)applicationDidEnterBackground:(UIApplication *)application { [tabBarController.view endEditing:YES]; } The keyboard does indeed get removed, but what I don't get is this: Apple's docs say that a snapshot of the app is taken

Asynchronous MPMoviePlayerController load has no duration value

丶灬走出姿态 提交于 2020-01-02 08:08:49
问题 I assume that the initWithContentURL: method is not asynchronous. I added the following methods to do the load in the background and then assign the temporary player to my variable. -(void)createPlayer { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; MPMoviePlayerController *temp = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:@"URLString"]]; [self performSelectorOnMainThread:@selector(passPlayer:) withObject:temp waitUntilDone:YES]; [temp release];

Displaying an Image from URL Objective C

落爺英雄遲暮 提交于 2020-01-02 07:17:11
问题 Is there any way of achieving the following that avoids using "initWithData" ? (Just in case you are curious, initWithData is getting my app flagged by Apple as using an illegal API sigh ). NSData * imageData = [NSData dataWithContentsOfURL : [NSURL URLWithString : [details image]]]; picture = [[UIImage alloc] initWithData:imageData]; Many thanks, Martin 回答1: First of all, you should do this asynchronously so that your thread won't block. Here is the code for the class: @implementation

Get User's Country

落爺英雄遲暮 提交于 2020-01-02 06:54:07
问题 I just wanted to know how I could find out the current user's country using Xcode (iPhone Dev SDK). 回答1: If you want to get the users country you can do two things. The easiest is to deciper it from their localization settings. NSLocale *locale = [NSLocale currentLocale]; NSString *country = [locale displayNameForKey:NSLocaleIdentifier value:[locale localeIdentifier]]; This can be unreliable (e.g. a user who is abroad). If you depend on the information you should use CoreLocation to find the

iOS 4 core motion attitude in landscape orientation

佐手、 提交于 2020-01-02 06:49:06
问题 I've been trying to rotate my view based on the CMAttitude returned from CMMotionManager specifically the pitch=x and roll=y. I'm using a reference attitude to set my horizon. This works great for portrait mode but the minute i try to do it for a landscape view it goes wrong. As the phone is now rotated 90 ccw I was hoping that coremotion would know landscape was in place and keep the pitch and roll useful. Instead I still have the axis pointing their original way. To try and compensate I

Remove part of an NSString

强颜欢笑 提交于 2020-01-02 05:06:24
问题 I have an NSString as follows: <img alt="996453912" src="http://d2gg0uigdtw9zz.cloudfront.net/large/996453912.jpg" /><a href="http://www.dealcatcher.com/shop4tech-coupons">Shop4Tech Coupons</a> I only need the first part (before the <a href part), and I cannot figure out how to remove the second part. I have tried a ton, but it has not worked. 回答1: Use something like: NSRange rangeOfSubstring = [string rangeOfString:@"<a href"]; if(rangeOfSubstring.location == NSNotFound) { // error condition

save bool in nsuserdefaults

左心房为你撑大大i 提交于 2020-01-02 03:01:04
问题 when my app starts music is playing: -(void)playBgMusic { NSString *path = [[NSBundle mainBundle] pathForResource:@"bgmusic" ofType:@"aif"]; theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL]; theAudio.delegate = self; [theAudio play]; } but he should be able to turn the music off by pressing a button if he presses the button again the music should turn on again. i have: -(IBAction)check { if (isquiet == NO) { [theAudio stop]; isquiet = YES;

Why is self.navigationItem.backBarButtonItem always nil?

走远了吗. 提交于 2020-01-02 01:01:15
问题 I push a view controller onto a navigation controller like this: [self.navigationController pushViewController:anotherViewController animated:YES]; And, then, inside anotherViewController I check self.navigationItem.BackBarButtonItem and LeftBarButtonItem, but they are always nil. I can see the backBarButtonItem, and it seems to work fine. 回答1: From the Documentation: "When this item is the back item of the navigation bar—when it is the next item below the top item—it may be represented as a

How to know when UITextView became first responder

99封情书 提交于 2020-01-01 23:10:56
问题 How to handle when uitextview became first responder. I have text in text view and I want when the view became active want to clear the text. How can I do that? Thanks in advance 回答1: You can definitely use a UITextViewDelegate method of: - (BOOL)textViewShouldBeginEditing:(UITextView *)textView Just return YES and intercept inside that method. You can also do it for UITextFields with UITextFieldDelegate and: - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField Hope that helps. 回答2:

Attach Local image in MMS in iphone

别说谁变了你拦得住时间么 提交于 2020-01-01 17:06:57
问题 I have one application in that I convert UIView in the image and send that file as an Email or an MMS. It is possible to send via Email using the addAttachmentData Method, but I can not find a similar solution for MMS. Is there an MMS solution similar to the Email solution? 回答1: There is no way to attach photos to the MMS sheet currently. Right now it is only for the Email sheet. 来源: https://stackoverflow.com/questions/4778680/attach-local-image-in-mms-in-iphone