cocoa-touch

eraser not working in iOS drawing

痞子三分冷 提交于 2019-12-28 03:10:07
问题 I am working on a drawing project, where I have an eraser option. The code given below is for when I start my app and draw some lines and the proceed to use the eraser. It works fine and I get the eraser effect. Now the second scenario is where I draw some 10 lines and then click on the "undo button" and undo the whole thing, then I redo the whole thing, and now when I click on the "eraser button" and try to erase some part, but instead, it will clear the whole drawing. This is what I am

NSString to NSArray

。_饼干妹妹 提交于 2019-12-28 02:15:12
问题 I want to split an NSString into an NSArray . For example, given: NSString *myString=@"ABCDEF"; I want an NSArray like: NSArray *myArray={A,B,C,D,E,F}; How to do this with Objective-C and Cocoa? 回答1: NSMutableArray *letterArray = [NSMutableArray array]; NSString *letters = @"ABCDEF𝍱क्"; [letters enumerateSubstringsInRange:NSMakeRange(0, [letters length]) options:(NSStringEnumerationByComposedCharacterSequences) usingBlock:^(NSString *substring, NSRange substringRange, NSRange enclosingRange,

Return a list of running background apps/processes in iOS

只愿长相守 提交于 2019-12-28 02:13:11
问题 I'm working on a jailbreak app, and want to send SIGKILL messages to specific apps that may be running on a user's device (with their permission, of course). Google is not turning up anything for me. Is there a plist or array that keeps track of running processes? Thanks for any help you all can give, you're wonderful! 回答1: Make a sysctl API and retrieve the kinfo_proc structure http://fxr.watson.org/fxr/source/sys/kinfo.h?v=DFBSD. This struct has information about running processes.You can

Responding to touchesBegan in UIPickerView instead of UIView

烈酒焚心 提交于 2019-12-28 02:11:47
问题 I have a UIPickerView that gets faded out to 20% alpha when not in use. I want the user to be able to touch the picker and have it fade back in. I can get it to work if I put a touchesBegan method on the main View, but this only works when the user touches the View. I tried sub-classing UIPickerView and having a touchesBegan in there, but it didn't work. I'm guessing it's something to do with the Responder chain, but can't seem to work it out. 回答1: I've been searching for a solution to this

How to make a superview intercept button touch events?

这一生的挚爱 提交于 2019-12-28 02:11:15
问题 Say I have this code: #import <UIKit/UIKit.h> @interface MyView : UIView @end @implementation MyView - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { // How can I get this to show up even when the button is touched? NSLog(@"%@", [touches anyObject]); } @end @interface TestViewAppDelegate : NSObject <UIApplicationDelegate> { UIWindow *window; } @end @implementation TestViewAppDelegate - (void)applicationDidFinishLaunching:(UIApplication *)application { window = [[UIWindow

Number of Occurrences of a Character in NSString

半腔热情 提交于 2019-12-28 02:06:04
问题 I have an NSString or NSMutableString and would like to get the number of occurrences of a particular character. I need to do this for quite a few characters -- uppercase English characters in this case -- so it would be nice for it to be quick. 回答1: replaceOccurrencesOfString:withString:options:range: will return the number of characters replaced in a NSMutableString . [string replaceOccurrencesOfString:@"A" withString:@"B" options:NSLiteralSearch range:NSMakeRange(0, [receiver length])];

Current Week Start and End Date

我与影子孤独终老i 提交于 2019-12-28 01:55:12
问题 I want to get the current week start and end date and I also want to use the previous week start and end date and next week of the start and end date in current month. Thanks in Advance. 回答1: rangeOfUnit:startDate:interval:forDate:. It gives you the start and the interval for a certain time unit. With it it is easy to find the start of the week in the used calendar and add the range-1 to get the latest second in that week. NSCalendar *cal = [NSCalendar currentCalendar]; NSDate *now = [NSDate

How to write a simple Ping method in Cocoa/Objective-C

最后都变了- 提交于 2019-12-27 19:12:58
问题 I need to write a simple ping method in Cocoa/Objective-C. It also needs to work on the iPhone. I found an example that uses icmp , will this work on the iPhone? I'm leaning towards a solution using NSNetServices , is this a good idea? The method only needs to ping a few times and return the average and -1 if the host is down or unreachable. 回答1: The code below seems to be working synchronously: const char *hostName = [@"stackoverflow.com" cStringUsingEncoding:NSASCIIStringEncoding];

Simple http post example in Objective-C?

好久不见. 提交于 2019-12-27 16:26:05
问题 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

Simple http post example in Objective-C?

蹲街弑〆低调 提交于 2019-12-27 16:26:00
问题 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