There exists a pair of functions NSStringFromCGPoint and CGPointFromString. You can use these to produce an array of strings representing the points for serialization, and then convert back when you're finished.
Friday, January 28, 2011
iPhone dev Stupidity 140: encode CGRect into NSUserDefaults
There exists a pair of functions NSStringFromCGPoint and CGPointFromString. You can use these to produce an array of strings representing the points for serialization, and then convert back when you're finished.
Tuesday, January 18, 2011
Monday, January 17, 2011
iPhone dev Stupidity 137: Understanding instruments allocations
ObjectAlloc tracks all memory allocation and deallocation over the time your program is running.
The Living bytes, or Net bytes is how much memory your application is using at the time you select in the timeline. That will include leaked memory, since leaked memory is never deallocated.
#Living is how many allocations of a certain size/object type happened (and are still allocated). This is very useful when looking for leaks. For example, if you repetitively perform an action (like coming in an out of a modal view controller), and you see that #Living of an object grows by the same amount each time, then you’re probably leaking those objects. You can then confirm by drilling down and seeing the exact line of code that is allocating the objects, and even see the time index each one was created.
Overall bytes includes memory that has been released. It’s useful to track that number for performance optimization purposes, but not if you’re just trying to see your current memory footprint or look for leaks.
http://stackoverflow.com/questions/2154219/instruments-objectalloc-explanation-of-live-bytes-overall-bytes
Saturday, January 15, 2011
iPhone dev Stupidity 136: Two stage animation warning
Using two-stage rotation animation. To use the smoother single-stage animation, this application must remove two-stage method implementations.
The real cause is from stackoverflow:
This message will appear if you have are presenting the UIImagePickerController within another UIViewController. Because it isn't pushed like a UINavigationController stack, there is confusion at the UIWindow level. I don't know if the warning is a problem, but to eliminate the warning you can do the following:
// self = a UIViewController
//
- (void) showCamera
{
cameraView = [[UIImagePickerController alloc] init];
[[[UIApplication sharedApplication] keyWindow] setRootViewController:cameraView];
[self presentModalViewController:cameraView animated:NO];
}
- (void) removeCamera
{
[[[UIApplication sharedApplication] keyWindow] setRootViewController:self];
[self dismissModalViewControllerAnimated:NO];
[cameraView release];
}
There’s also a good point for iOS 4.x:
Perhaps you are adding the root UIViewController's view as a subview of the window instead of assigning the view controller to the window's rootController property?
Tuesday, November 23, 2010
iPhone dev Stupidity 135: Codesign error
Sometimes your xcode project file gets messed up, especially if you have an old project and first created it with an older version of xcode/iphone sdk. What you need to do is open up the project file in a text editor, search from the long sting and manually erase that line. In fact, you should just go aead and erase any line that points to any provisioning profiles. Then reopen the project in xcode, go to the settings are reselect your new profile. This clears up issues like that most of the time The lines that point to the provisioning profiles will look like this:
PROVISIONING_PROFILE = "487F3EAC-05FB-4A2A-9EA0-31F1F35760EB";
"PROVISIONING_PROFILE[sdk=iphoneos*]" = "487F3EAC-05FB-4A2A-9EA0-31F1F35760EB";
iPhone dev Stupidity 134: Core Animation doc reading
* Sublayers do not clip to parent by default (UIView does). To enable, theLayer.masksToBounds = YES
* To position content image in a CALayer:
* You can stop an animation by: removeAnimationForKey:
- (void)runActionForKey:(NSString *)key
object:(id)anObject
arguments:(NSDictionary *)dict
{
[(CALayer *)anObject addAnimation:self forKey:key];
}
iPhone dev Stupidity 133: switch action for button
@implementation UIButton (Ext)
- (void) switchToAction: (SEL) newSelector forControlEvents: (UIControlEvents) event{
// get the old target/action pair
NSSet * targets = [self allTargets];
assert(targets.count == 1);
id target = [targets anyObject];
NSArray * action_strs = [self actionsForTarget: target forControlEvent: event];
assert(action_strs.count == 1);
NSString * action_name = [action_strs objectAtIndex: 0];
SEL action = NSSelectorFromString(action_name);
// remove it
[self removeTarget: target action: action forControlEvents: event];
// set new selector
[self addTarget: target action: newSelector forControlEvents: event];
}
@end
iPhone dev Stupidity 132: Sending picture attachment via email
// Attach image data to the email
// 'CameraImage.png' is the file name that will be attached to the email
[picker addAttachmentData:data mimeType:@"image/png" fileName:@"CameraImage"];
Yes. You can attache multiple images.
iPhone dev Stupidity 131: Quartz 2d coords
Thursday, June 10, 2010
iPhone dev Stupidity 130: antialiasing on a rotated view
Wednesday, June 09, 2010
iPhone dev Stupidity 129: -all_load -ObjC linker flag in Xcode
From Apple Q&A
Q: Why do I get a runtime exception of "selector not recognized" when linking against an Objective-C static library that contains categories?
A: The "selector not recognized" runtime exception occurs due to an issue between the implementation of standard UNIX static libraries, the linker and the dynamic nature of Objective-C. Objective-C does not define linker symbols for each function (or method, in Objective-C) - instead, linker symbols are only generated for each class. If you extend a pre-existing class with categories, the linker does not know to associate the object code of the core class implementation and the category implementation. This prevents objects created in the resulting application from responding to a selector that is defined in the category.
To resolve this issue, the target linking against the static library must pass the -ObjC option to the linker. This flag causes the linker to load every object file in the library that defines an Objective-C class or category. While this option will typically result in a larger executable (due to additional object code loaded into the application), it will allow the successful creation of effective Objective-C static libraries that contain categories on existing classes. Follow these steps to pass -ObjC to the linker:
In Xcode, double-click the target's name under "Targets" in the Project window.
Choose the Build pane from the ensuing Info window.
Scroll down to the Other Linker Flags build setting under the Linking collection and set its value to -ObjC.
Figure 1: Target Build pane: Other Linker Flags
IMPORTANT: For 64-bit and iPhone OS applications, there is a linker bug that prevents -ObjC from loading objects files from static libraries that contain only categories and no classes. The workaround is to use the -all_load or -force_load flags.
-all_load forces the linker to load all object files from every archive it sees, even those without Objective-C code. -force_load is available in Xcode 3.2 and later. It allows finer grain control of archive loading. Each -force_load option must be followed by a path to an archive, and every object file in that archive will be loaded.
iPhone dev Stupidity 128: Photo orientation issue in Three20’s TT
iPhone dev Stupidity 127: How Three20 works
1. Create TTThumbesViewController via URL: "tt:\\phototest2"
2. When is the TTURLMap setuped?
3. And mapped to class
[map from:@"*" toViewController:[TTWebController class]];
[map from:@"tt://catalog" toViewController:[CatalogController class]];
[map from:@"tt://photoTest1" toViewController:[PhotoTest1Controller class]];
[map from:@"tt://photoTest2" toViewController:[PhotoTest2Controller class]];
4. How TTThumbsView get created?
5. URL protocol
6. A Tutorial on How to create a photo browser using Three20
iPhone dev Stupidity 126: private folder for images
//I do this in the didFinishPickingImage:(UIImage *)img method
NSData* imageData = UIImageJPEGRepresentation(img, 1.0);
//save to the default 100Apple(Camera Roll) folder.
[imageData writeToFile:@"/private/var/mobile/Media/DCIM/100APPLE/customImageFilename.jpg" atomically:NO];
The photos there are all named in IMG_####.JPG format.
NSArray *directoryContent = [[NSFileManager defaultManager] directoryContentsAtPath:@"/private/var/mobile/Media/DCIM/100APPLE/.MISC"];
for(NSString * dir in directoryContent){
NSLog(dir);
}
iPhone dev Stupidity 125: lack of EXIF with the iPhone API
iPhone dev Stupidity 124: Rotating view around arbitrary point th
iPhone dev Stupidity 123: How to launch iPhone Camera on viewDidL
You should do it in viewWillAppear:, or viewDidAppear: if the first doesn't work. trying to do it in viewDidLoad won't work because that is called after the view is first created, and the view isn't a subview of anything else at that point.
UIImageView animationImages
imageView.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"cameraScreenOverlay1.png"],
[UIImage imageNamed:@"cameraScreenOverlay2.png"],
[UIImage imageNamed:@"cameraScreenOverlay3.png"],
[UIImage imageNamed:@"cameraScreenOverlay4.png"],
[UIImage imageNamed:@"cameraScreenOverlay4.png"],
[UIImage imageNamed:@"cameraScreenOverlay4.png"],
[UIImage imageNamed:@"cameraScreenOverlay3.png"],
[UIImage imageNamed:@"cameraScreenOverlay2.png"],
[UIImage imageNamed:@"cameraScreenOverlay1.png"],
nil];
imageView.animationDuration = 1.0;
imageView.animationRepeatCount = 0;
[imageView startAnimating];
doesn't work when imageView is used as an overlay view above camera.
iPhone dev Stupidity 122: Customize bars, buttons, status bar
4. Hiding status bar via .plist