Wednesday, October 28, 2009
iPhone dev Stupidity 92: get content view of UIScrollView
iPhone dev Stupidity 91: Image Refelection
- (UIImage *)reflectedImageRepresentationWithHeight:(NSUInteger)height;
CGImageRef AEViewCreateGradientImage (int pixelsWide, int pixelsHigh);
iPhone dev Stupidity 90: SMS Balloon
UIImage * img = [UIImage imageNamed: @"balloon.png"];
g_balloon_ = [[img stretchableImageWithLeftCapWidth: img.size.width/2 topCapHeight: img.size.height/2] retain];
assert(g_balloon_.leftCapWidth == (int)(img.size.width/2));
Tuesday, October 27, 2009
iPhone dev Stupidity 89: SMS send
Monday, October 26, 2009
iPhone dev Stupidity 88: SQL reverse ordering
iPhone dev Stupidity 87: Timezone & Date formatter
3. Date Formatter from [iPhone developer: tips];
Sunday, October 25, 2009
iPhone dev Stupidity 86: Upgrade - how to import old data
"I think the short answer is yes, the only sensible option are webservices. There is no iTunes sync plugin that you can use so your options are all network based.
Other than webservices, you might also like to consider a client-side program that your iPhone app finds and connects to using Bonjour. The obvious disadvantage here is that you have to write client apps (preferably two, one for Windows the other for Mac) and educate your users on how to download and install them. Also you're forcing your users to sync using WiFi."
Saturday, October 24, 2009
iPhone dev Stupidity 85: change animation style of UIViewControll
IViewController * controller = [[[MyViewController alloc] init] autorelease];
UIViewAnimationTransition trans = UIViewAnimationTransitionCurlUp;
[UIView beginAnimations: nil context: nil];
[UIView setAnimationTransition: trans forView: [self window] cache: YES];
[navController presentModalViewController: controller animated: NO];
[UIView commitAnimations];
iPhone dev Stupidity 84: Use symbolic break point to detect chang
10 breakpoint keep y 0x309323fd <-[UINavigationBar setBarStyle:]+6>
Wednesday, October 21, 2009
iPhone dev Stupidity 83: you can't hijack the "back" button
iPhone dev Stupidity 82: change the title of "back" button in nav
// set the category
// .. get parent
NSArray * viewControllerArray = [self.navigationController viewControllers];
int parentViewControllerIndex = [viewControllerArray count] - 2;
UIViewController * parent_vc = [viewControllerArray objectAtIndex: parentViewControllerIndex];
// .. if the category changed
if(![parent_vc.navigationItem.backBarButtonItem.title isEqualToString: cat_name]){
// update the back button title
UIBarButtonItem *newBackButton = [[UIBarButtonItem alloc] initWithTitle: cat_name style: UIBarButtonItemStyleBordered target: nil action: nil];
parent_vc.navigationItem.backBarButtonItem = newBackButton;
[newBackButton release];
}
iPhone dev Stupidity 81: SQLite3 Cursor?
Tuesday, October 20, 2009
iPhone dev Stupidity 80: SQLite3 counting rows
NSString * sql = [NSString stringWithFormat: @"SELECT count(0) from %@ WHERE %@ = %d", table, colName, val];
sqlite3_stmt *compiledStatement;
if(sqlite3_prepare_v2(database_, [sql UTF8String], -1, &compiledStatement, NULL) == SQLITE_OK) {
int count = 0;
if(sqlite3_step(compiledStatement) == SQLITE_ROW){
count = sqlite3_column_int(compiledStatement, 0);
}
sqlite3_finalize(compiledStatement);
return count;
}
Wednesday, October 14, 2009
Tuesday, October 13, 2009
iPhone dev Stupidity 79: How to track double free
Sunday, October 11, 2009
iPhone dev Stupidity 78: Learned from iPhone developer Meeting
-----------
1. Sample code for App Store style table
2. - (UIImage *)stretchableImageWithLeftCapWidth:(NSInteger)leftCapWidth topCapHeight:(NSInteger)topCapHeight
3. User generated content must rated as 17+
4. error 101 usually means low memory warning
5. XCode 3.2 -> Settings -> General -> Accessiblity Inspetor: for UI debug
7. Social networking/Forum need to provide Apple a functional account for review
8. tableView:titleForDeleteConfirmationButtonForRowAtIndexPath:
Changes the default title of the delete-confirmation button.
Make sure the title is not too long to cover the table cell content - If it's SDK's bug, do not count on it.
9. If using system icon lead to user confusion, do NOT use it
READ the HIG word by word.
10. Serch Bar:
1) tableHeaderView as a searchBar
2) delegate
11. Clear Release Note:
- which screen, what changes
- if not sure, release as "bug fix"
12. Q/A:
1) localization: use less IB. Take care of label length.
2) Cocoa cookbook: non offical API - on your own risk
3) Ad hoc deploy: iTunes will change .app -> .ipa to send. (Packing may change the app code sign)
4) Use UIDevice to get the SDK version number.
Talk 2 : iPhone Data Managment
------------------
1. SQLite
1) Sample code: SQLiteBooks
2) copy sqlite.db from resource to writable folder (Document) - for safty.
3) Shrink the db file size: sqlite > vacuum
4) Document folder is resevered when upgrade
5) >50MB file, copy failed
. - (BOOL)createSymbolicLinkAtPath:(NSString *)path pathContent:(NSString *)otherPath
. seperate db fields - leave big & read only one in resouce, only copy the small & editable fields to document folder.
6) Design schema with consideration for upgrade
. keep version in db
. sql script to choose different db via version.
2. XML
. RSS
. API via http
3. Ordered as: idea, marketing, tech.
Talk 3: SQLite & Core Data
----------------------
1. Browser: sqlitebrowser.sourceforge.net
2. Multi-platform use SQLite
3. Core Data on logic level; and optimized for caching, lazy-loading and memory management; KVO/KVC; undo/redo.
Talk 4: Three 20 Kit
----------------
Controls:
1. New message/mail
2. Styled fonts
3. Activity labels/progress bar
- screen lock styled label - glowing effect
4. Launcher
--
Concept:
1. Style: like CSS
2. using 'next' to combine different styles
3. URL: can point to res, view controller
- "bundle://..."
- "documents://..."
Talk 5: Core Animation
-------------------
Talk 6: Multi Touch
----------------
1. Use 2 fingers touch to drag canvas
2. Multi touch levels: 1 -> 2 -> 3 increase
3. app:
. SmartChoice
. OthelloCube
Talk 7: iFighter
------------
1. Lite before non-free version: get feedback for final version. iFighter used 1.5 month.
2. Promc code for promotion
3. Tips:
- old topic but be the best
- monkey -> hardcore: adapt to users of different levels
- great service to keep users
- only make the great product -> from product to brand
- share the success
4. Q/A:
. 3 peoples to make iFighter
. personal product to company product - refund if users have difficult to transfer
. why don't ship paied version when lite version is asending
. self made game engine
. made in home
. peer review, defining the great
. the product finishs where you stop working it
. price -> confidence in the product: check the sales chart.
. ccgamebox 2d engine
.
iPhone dev Stupidity 76: setNeedsDisplay is not free
iPhone dev Stupidity 75: melt at corner
Use CGGradient in linear mode, once for each side. But for this to work, I think I'd need to set up a trapezoidal clipping area for each side first, so that the gradients would be mitered at the corners.
Using NSBezierPath to create the trapezoidal regions would be fairly straightforward, and you would only have to perform four drawing operations.
Here's the basic code for creating the left side trapezoidal region:
NSRect outer = [self bounds];
NSPoint outerPoint[4];
outerPoint[0] = NSMakePoint(0, 0);
outerPoint[1] = NSMakePoint(0, outer.size.height);
outerPoint[2] = NSMakePoint(outer.size.width, outer.size.height);
outerPoint[3] = NSMakePoint(outer.size.width, 0);
NSRect inner = NSInsetRect([self bounds], borderSize, borderSize);
NSPoint innerPoint[4];
innerPoint[0] = inner.origin;
innerPoint[1] = NSMakePoint(inner.origin.x,
inner.origin.y + inner.size.height);
innerPoint[2] = NSMakePoint(inner.origin.x + inner.size.width,
inner.origin.y + inner.size.height);
innerPoint[3] = NSMakePoint(inner.origin.x + inner.size.width,
inner.origin.y);
NSBezierPath leftSidePath = [[NSBezierPath bezierPath] retain];
[leftSidePath moveToPoint:outerPoint[0]];
[leftSidePath lineToPoint:outerPoint[1]];
[leftSidePath lineToPoint:innerPoint[1]];
[leftSidePath lineToPoint:innerPoint[0]];
[leftSidePath lineToPoint:outerPoint[0]];
// ... etc.
[leftSidePath release];
iPhone dev Stupidity 74: UIScrollView beyond bounds gradient?
// Setup top most gradient parameters and clipping mask.
CGPoint startPoint = CGPointMake(rect.origin.x, rect.origin.y);
CGPoint endPoint = CGPointMake(0.0, shadowHeight_);
CGRect clipRect = CGRectMake(rect.origin.x, rect.origin.y, rect.size.width, shadowHeight_);
// Draw top most gradient within clipped rect. Look at Quartz Demo for details.
CGContextSaveGState(context);
CGContextClipToRect(context, clipRect);
CGContextDrawLinearGradient(context, gradient, startPoint, endPoint, 0);
CGContextRestoreGState(context);
CGColorSpaceRef rgb = CGColorSpaceCreateDeviceRGB();
CGFloat colors[] = {
//0.0, 0.0, 0.0, 0.5,
//1.0, 1.0, 1.0, 0.0
65.0/256, 81.0/256, 81.0/256, 1.0,
0.0, 0.0, 0.0, 1.0,
};
gradient = CGGradientCreateWithColorComponents(rgb, colors, NULL, 2);
CGColorSpaceRelease(rgb);
iPhone dev Stupidity 73: memory alignment.
"All allocations that use the OS X supplied malloc are aligned to 16 bytes. You've clearly tried to free something that isn't so it's invalid."
iPhone dev Stupidity 72: Get the RGB of a Pixel
iPhone dev Stupidity 71: Loading ... 17% - How to Make progress b
- (void) sendProgressNotification: (NSNumber *) percentDeltaValue{
[[NSNotificationCenter defaultCenter] postNotificationName:@"StepPercent" object: percentDeltaValue];
}
// post the progress info
- (void) stepPercentage: (int) percentDelta{
[NSThread detachNewThreadSelector: @selector(sendProgressNotification:) toTarget: self withObject: [NSNumber numberWithInt: percentDelta]];
}
iPhone dev Stupidity 70: Profile to make proper progress percenta
2009-08-13 17:22:52.063 Flip[368:207 ] splash awake took 130.620000 ms!
2009-08-13 17:22:53.152 Flip[368:3f03] create scrollview took 11.913333 ms!
2009-08-13 17:22:53.164 Flip[368:3f03] loading ... 5
2009-08-13 17:22:54.412 Flip[368:3f03] create matrix took 1223.421500 ms!
2009-08-13 17:22:54.427 Flip[368:3f03] loading ... 15
2009-08-13 17:22:54.633 Flip[368:3f03] add texels took 173.522666 ms!
2009-08-13 17:22:54.646 Flip[368:3f03] loading ... 15
2009-08-13 17:22:54.662 Flip[368:3f03] create flipview took 1478.210500 ms!
2009-08-13 17:22:55.010 Flip[368:3f03] create background view took 335.918166 ms!
iPhone dev Stupidity 69: DEBUG flag
iPhone dev Stupidity 68: Handcraft Profiler
#include <mach/mach_time.h>
#define START_PROFILE(name)\
{\
const char * msg = name;\
mach_timebase_info_data_t info;\
mach_timebase_info(&info);\
uint64_t start = mach_absolute_time();
#define END_PROFILE\
uint64_t duration = mach_absolute_time() - start;\
duration *= info.numer;\
duration /= info.denom;\
NSLog(@"%s took %lld nanoseconds!", msg, duration);\
}
To use:
iPhone dev Stupidity 67: Symbol break point
(gdb) b resignFirstResponder
[0] cancel
[1] all
Non-debugging symbols:
[2] -[UIFieldEditor resignFirstResponder]
[3] -[UIPreferencesTextTableCell resignFirstResponder]
[4] -[UIResponder resignFirstResponder]
[5] -[UISearchBar(UISearchBarStatic) resignFirstResponder]
[6] -[UITextContentView resignFirstResponder]
[7] -[UITextField resignFirstResponder]
[8] -[UITextView resignFirstResponder]
[9] -[UIWebDocumentView resignFirstResponder]
[10] -[WAKResponder resignFirstResponder]
[11] -[WebHTMLView resignFirstResponder]
> 7
Breakpoint 9 at 0x30962ba0
(gdb) i b
Num Type Disp Enb Address What
1 breakpoint keep y 0x0000a037 in -[Texel dealloc] at /Users/Carrie/MyProjects/Sandbox/Flip/Classes/Texel.m:108
2 breakpoint keep y <PENDING> "TestUtility.m:18
3 breakpoint keep y 0x0002320b in -[TemplateDB dealloc] at /Users/Carrie/MyProjects/Sandbox/Flip/Classes/TemplateDB.m:66
4 breakpoint keep y 0x0000acc3 in -[Texel singleTapped] at /Users/Carrie/MyProjects/Sandbox/Flip/Classes/Texel.m:257
5 breakpoint keep y 0x0000ac53 in -[Texel killEditor] at /Users/Carrie/MyProjects/Sandbox/Flip/Classes/Texel.m:249
6 breakpoint keep y 0x00008548 in -[GlassView changed:With:] at /Users/Carrie/MyProjects/Sandbox/Flip/Classes/GlassView.m:300
breakpoint already hit 1 time
7 breakpoint keep y 0x9360637c <__assert_rtn+6>
8 breakpoint keep y 0x9360637c <__assert_rtn+6>
9 breakpoint keep y 0x30962ba0 <-[UITextField resignFirstResponder]+6>