objective-c
Merging NSArrays in Objective-C
Just use [newArray addObjectsFromArray:anArray];
Convert a string (“MyExampleClass”) into a class name (MyExampleClass)
Here’s what you’d want: Class theClass = NSClassFromString(classNameStr); id myObject = [[theClass alloc] init]; Note that you can’t use theClass as a type name (i.e. theClass *myObject). You’ll have to use id for that.
How to form CGPoint array in Objective-C?
For iOS: Create array: NSArray *myCGPointArray = @[[NSValue valueWithCGPoint:CGPointMake(30.0, 150.0)],[NSValue valueWithCGPoint:CGPointMake(41.67, 145.19)]]; Get 1st CGPoint object: CGPoint myPoint = [myCGPointArray[0] CGPointValue];
Display each item in an NSDictionary
Try this code for(NSString *key in [dict allKeys]) { NSLog(@”%@”,[dict objectForKey:key]); }
UIProgressView and Custom Track and Progress Images (iOS 5 properties)
Here’s what’s going on: The images you provide to the UIProgressView are basically being shoved in to UIImageViews, and the UIImageView is stretching the image to fill the space. If you simply do: [progressView setTrackImage:[UIImage imageNamed:@”track.png”]]; Then you’re going to get weird results, because it’s trying to stretch a 10px wide image to fill (for … Read more
NSTextField – White text on black background, but black cursor
Since in practice the NSText* returned by -currentEditor for an NSTextField is always an NSTextView*, I added the following code to my custom NSTextField subclass: -(BOOL) becomeFirstResponder { BOOL success = [super becomeFirstResponder]; if( success ) { // Strictly spoken, NSText (which currentEditor returns) doesn’t // implement setInsertionPointColor:, but it’s an NSTextView in practice. // … Read more
How to detect touches on UIImageView of UITableViewCell object in the UITableViewCellStyleSubtitle style
In your cellForRowAtIndexPath method add this code cell.imageView.userInteractionEnabled = YES; cell.imageView.tag = indexPath.row; UITapGestureRecognizer *tapped = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(myFunction:)]; tapped.numberOfTapsRequired = 1; [cell.imageView addGestureRecognizer:tapped]; [tapped release]; And then to check which imageView was clicked, check the flag in selector method -(void)myFunction :(id) sender { UITapGestureRecognizer *gesture = (UITapGestureRecognizer *) sender; NSLog(@”Tag = %d”, gesture.view.tag); … Read more