cocoa-touch

load local HTML file when link is clicked in WebView

…衆ロ難τιáo~ 提交于 2019-12-30 12:54:05
问题 I have a WebView that loads a local HTML file like this: [webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"test1" ofType:@"html"]isDirectory:NO]]]; What I want is to click a link in the test1 local HTML file and then for the webView to load the test2 local HTML file. How can I do this? 回答1: Like in a regular webpage. Let the link in test 1 point to test2. 回答2: Instead of loading a request, use the - (void)loadHTMLString:(NSString

UITextField - Dismiss keyboard when two digits have been entered

孤人 提交于 2019-12-30 12:25:11
问题 I have a UITextField, which uses a number pad to take input. How can I dismiss it/run a method call when two digits have been entered into the textField? 回答1: -(BOOL) textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{ int count = [textField.text length]; if(count>=2){ [textField resignFirstResponder]; } return YES; } 回答2: Use the text field delegate method: - (BOOL)textField:(UITextField *)textField

Can't use reloadData from another class

陌路散爱 提交于 2019-12-30 11:28:06
问题 I have 2 classes, classA and classB In classA I have a tableview that works and refreshes on demand. all the delegates and datadource are fine and there's also a property @property (nonatomic, retain) UITableView *myTableView; I don't want to put reloadData in viewDidAppear or viewWillAppear of classA. I want to fire [myTable reloadData] from classB. Thanks 回答1: Use delegates to reload your tableview. In the class where the tableview is, write this in viewDidLoad: [[NSNotificationCenter

iPhone: available disk space

折月煮酒 提交于 2019-12-30 10:33:15
问题 I am creating an audio-recording application and I need to know how much disk space is available (not ram). How can I retrieve it? Thanks. 回答1: I haven't tried this, but since the iPhone is a UNIX based OS you should be able to get the free space on the flash file system using the statfs system call (see link for documentation). Just use as parameter the path to the app directory that you plan to write to. 回答2: Best solution for me is to use the NSFileManager method: - (NSDictionary *

How to send and receive data in Today extensions

删除回忆录丶 提交于 2019-12-30 10:14:27
问题 I want to develop an app for iOS that have a Widget for notification center, but I don't know how I should send and receive data (pass data) between View Controller and And Today Extension. I tried to use structs, but it doesn't work, and also I used app groups but I don't want to use this method. let shared = NSUserDefaults(suiteName: "group.Demo.Share-Extension-Demo.mahdi") shared?.setObject("Hello", forKey: "kkk") 回答1: Apart from NSUserDefaults, you can use the NSNotificationCenter to send

CGImageCreateWithImageInRect not Cropping Correctly

馋奶兔 提交于 2019-12-30 10:07:11
问题 I'm having a hell of a time using CGImageCreateWithImageInRect to crop a photo. My app has the user move / enlarge an image till it fills a 316 x 316 view, then I want it to crop off any area outside the box and save the image as a UIImage. I determine the crop origin by taking the absolute value of the x and y imageview origin as that brings me back to 0,0 of the view / box that contains the imageview. Below is the code: CGRect croppedRect = CGRectMake(fabs(widthDistanceToOrigin), fabs

Two buttons in a UITableViewCell: How to tell which indexPath was selected?

不羁岁月 提交于 2019-12-30 09:50:11
问题 I want to place two buttons in each table view cell. When I click on button number one I want the app to show an alert message: "You tapped button1 at indexpath:3,0". My problem is: how can I place the buttons in a table view cell? Can anyone guide me? 回答1: Taking @wedo's answer and simplifying it a bit -- you essentially need two pieces of information : the row and column number that was tapped ("column" being the order of the button). Solution 1 - Not a Bad Solution This can be stored on a

Two buttons in a UITableViewCell: How to tell which indexPath was selected?

故事扮演 提交于 2019-12-30 09:50:04
问题 I want to place two buttons in each table view cell. When I click on button number one I want the app to show an alert message: "You tapped button1 at indexpath:3,0". My problem is: how can I place the buttons in a table view cell? Can anyone guide me? 回答1: Taking @wedo's answer and simplifying it a bit -- you essentially need two pieces of information : the row and column number that was tapped ("column" being the order of the button). Solution 1 - Not a Bad Solution This can be stored on a

Dismissing modal view controller stack

做~自己de王妃 提交于 2019-12-30 09:49:31
问题 Given the following view controller layout. We build a stack of modal view controllers by first presenting B on A and then presenting C on B . According to the Apple documentation on dismiss(animated:completion:), calling it on A should actually dismiss the topmost view controller ( C in this case) in an animated fashion and all intermediate view controllers without animation. What happens though is that C gets dismissed without animation and B is dismissed in an animated fashion. I put up an

-[NSInputStream read:maxLength:] throws an exception saying length is too big, but it isn't

限于喜欢 提交于 2019-12-30 09:44:10
问题 I use an NSInputStream to read data from a file. It will crash if maxLength is greater than 49152. When it crashes -- sometimes, but not every time, it gives this message: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSConcreteData initWithBytes:length:copy:freeWhenDone:bytesAreVM:]: absurd length: 4294967295, maximum size: 2147483648 bytes' From my calculation, 524288 is still less than that maximum, and can fit in the return value. What did I