Tuesday, December 29, 2009
iPhone dev Stupidity 116: How to find out what mach_msg_trap wait
Wednesday, December 16, 2009
iPhone dev Stupidity 115: UITableView delete section
[self.tableView deleteSections: [NSIndexSet indexSetWithIndex: section] withRowAnimation: UITableViewRowAnimationLeft];
Tuesday, December 15, 2009
iPhone dev Stupidity 114: Muliti column order
SELECT * FROM Individual
ORDER BY FirstName, LastName
2. We want to sort files by name - when two files have the same name we sort them by the date time:
NSString * sql = [NSString stringWithFormat: @"SELECT arts.*, tags.name FROM arts, tags WHERE category_id = %d and arts.tag_1 = tags.tag_id and ((tags.name = '%@' and arts.date_touched > '%@') or tags.name > '%@') ORDER BY tags.name LIMIT 1", cur_art.category_id_, cur_name, cur_art.date_touched_, cur_name];
iPhone dev Stupidity 113: Write protection of Resource
Sunday, December 13, 2009
iPhone dev Stupidity 112: SQLite, Last inserted row id
Wednesday, December 09, 2009
iPhone dev Stupidty 111: SQL table order
Monday, November 30, 2009
iPhone dev Stupidity 110: Fine Grained Observing for Text Field
[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(textFieldTextDidChange:) name: @"UITextFieldTextDidChangeNotification" object: nil];
UIKIT_EXTERN NSString *const UITextFieldTextDidBeginEditingNotification;
UIKIT_EXTERN NSString *const UITextFieldTextDidEndEditingNotification;
UIKIT_EXTERN NSString *const UITextFieldTextDidChangeNotification;
// UITextField.h
// UIKit
//
// Copyright 2005-2009 Apple Inc. All rights reserved.
iPhone dev Stupidity 109: NSAttributedString, NSFormatter for UIT
Sunday, November 29, 2009
iPhone dev Stupidity 108: Scrolled UITextField
Saturday, November 28, 2009
iPhone dev Stupidity 107: LuaFileSystem
To use LuaFileSystem, we need LuaRocks to install the lfs package.
iPhone dev Stupidity 105: Confuse alpha = 0.0 with remove
Wednesday, November 25, 2009
iPhone dev Stupidity 104: Update Navigation Bar
A UINavigationBar object uses a stack to manage navigation items (instances of UINavigationItem) that represent a state of the navigation bar. You change the navigation bar by pushing navigation items using the pushNavigationItem:animated: method or popping navigation items using thepopNavigationItemAnimated: method. Methods with an animated: argument allow you to animate the changes to the display.
2009-11-26 07:45:11.742 Flip[404:20b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Cannot call pushNavigationItem:animated: directly on a UINavigationBar managed by a controller.'
Monday, November 23, 2009
iPhone dev Stupidity 102: Do you have to release IBOutlet?
from stackoverflow:
Your IBOutlets are probably @properties. If they are, and you have retain as an attribute, then you do need to release in -dealloc
A best practice:
self.myoutlet = nil; in dealloc
This works for both the retained and assigned IBOutlet. The retained will release and the assigned will do nothing.
iPhone dev Stupidity 103: NSZombie and Memory leaks
from here:
NSZombieEnabled creates leaks ON PURPOSE so you can track down calls to objects that are released prematurely. When you run with NSZombieEnabled, objects are never dealloced. When it's time to dealloc the object, NSZombieEnabled tells the runtime to turn the object into an instance of NSZombie. Any attempt to message an NSZombie will result in a runtime exception. Always remember to remove the NSZombieEnabled flag before sending an app into production! Due to the fact that dealloc is overridden, your app will never free any memory - it will just grow and grow. It's for testing and debugging only.
iPhone dev Stupidity 101: How to draw text vertically?
1. Drawing NSString in unusual direction : limited to ascii string and have effect like this:
use CGContextShowText(ctxt, tbuf.c_str(), tbuf.length()); and CGAffineTransform
2. CGFontGetGlyphsForUnichars
to draw unichar we need this function to get glyph out of a unichar. Then core graphic has a set of function for showing glyph like this one:
void CGContextShowGlyphsAtPoint (
CGContextRef c,
CGFloat x,
CGFloat y,
const CGGlyph glyphs[],
size_t count
);
but CGFontGetGlyphsForUnichars is a private API for iPhone. So we got:
3. A replacement for CGFontGetGlyphsForUnichars
on github
-----
4. bonus: draw gradient filled UILabel.
also uses: extern void CGFontGetGlyphsForUnichars(CGFontRef, const UniChar[], const CGGlyph[], size_t);
iPhone dev Stupidity 100: viewDidUnload
From apple doc:
Called when the controller’s view is released from memory.
- (void)viewDidUnload
Discussion
This method is called as a counterpart to the viewDidLoad method. It is called during low-memory conditions when the view controller needs to release its view and any objects associated with that view to free up memory.
iPhone dev Stupidity 99: Start/End of a scrolling (with drag)
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
Wednesday, November 11, 2009
iPhone dev Stupidity 98: Bar place holder for view
Monday, November 02, 2009
iPhone dev Stupidity 97: SVN Locked
iPhone dev Stupidity 95: Non freed memory
iPhone dev Stupidity 94: Delete content of scrollview when scroll
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
later there's still some animation work need to be done by cocoa, and the error will happen (note that ScrollerHeartbeatCallback):
// !!! a hack
// directly remove container from superview, later there's some heart beat callback for smoothing the scrolling
// which will still trying to use the old scroller, and when fails to find, there'll be a BAD ACCESS failure
// here we just delay the remove.
container.alpha = 0.0;
[container performSelector: @selector(removeFromSuperview) withObject: nil afterDelay: 0.1];
iPhone dev Stupidity 93: Nested UIScrollView
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];