Tuesday, July 27, 2010

double tap

float distance;
if([touches count] == 2) {
// Order touches so they're accessible separately
NSMutableArray *touchesArray = [[[NSMutableArray alloc]
initWithCapacity:2] autorelease];
for(UITouch *aTouch in touches) {
[touchesArray addObject:aTouch];
}
UITouch *firstTouch = [touchesArray objectAtIndex:0];
UITouch *secondTouch = [touchesArray objectAtIndex:1];

// Do math
CGPoint firstPoint = [firstTouch locationInView:[firstTouch view]];
CGPoint secondPoint = [secondTouch locationInView:[secondTouch view]];
distance = sqrtf((firstPoint.x - secondPoint.x) *
(firstPoint.x - secondPoint.x) +
(firstPoint.y - secondPoint.y) *
(firstPoint.y - secondPoint.y));
}

show image in center of table view

CGRect frame;

frame= CGRectMake(230 ,50, 50, 50);
UIImageView * myImageView = [[UIImageView alloc]init];
myImageView.image = [UIImage imageNamed:@"bowl.png"];
//cell.imageView.image= [UIImage imageNamed:@"bowl.png"];

myImageView.frame = frame;
//UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bowl.png"]];
[cell.contentView
addSubview: myImageView];
[myImageView release];

Thursday, July 22, 2010

C in UNIX

gcc -c test.c
$ gcc test.c
$ gcc test.c -o a.out
$ ./a.out



thats it HAPPY CODING :-)

Wednesday, July 21, 2010

How to Debug an iPhone App Crash, Part 1: EXC_BAD_ACCESS

1. Run Build and Analyze: This kind of Build is very good at finding retain/release bugs. Take a good look at everything it flags.
2. Even better, run scan-build. I did a test recently, and found that some common errors are off by default in Build and Analyze that can be turned on in scan-build.
3. Choose Run > Enable Guard Malloc in the menu, and then re-run your application. This finds a whole class of buffer overrun issues. If this detects it, you’ll see a better error in the console.
4. You can instruct the compiler to ignore release calls and then report if anyone is sending messages to objects that would have been deallocated. This results in much better errors in the Console if it detects them.
5. Valgrind is the gold standard for finding memory bugs on Linux, and here’s a way to get it working in the iPhone Simulator.



Thanks to http://www.loufranco.com/blog/files/debug-iphone-crash-EXC_BAD_ACCESS.html

Friday, July 16, 2010

Adding images to map Annotation

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:
(id )annotation {
if (annotation == mapView.userLocation) return nil;

UIImage *anImage = nil;
if([[annotation title] isEqualToString:@"type1"])
{
anImage=[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"type1.png" ofType:nil]];
}
else if([[annotation title] isEqualToString:@"type2"])
{
anImage=[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"type2.png" ofType:nil]];
}
else if([[annotation title] isEqualToString:@"type3"])
{
anImage=[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"type3.png" ofType:nil]];
}
else if([[annotation title] isEqualToString:@"type4"])
{
anImage=[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"type4.png" ofType:nil]];
}

MKAnnotationView *anView=(MKAnnotationView*)[mapView
dequeueReusableAnnotationViewWithIdentifier:@"annotation"];

if(anView==nil){
anView=[[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"annotation"] autorelease];
}
anView.image = anImage;
anView.annotation=annotation;
anView.canShowCallout=YES;
if(tag==0){
anView.rightCalloutAccessoryView=[UIButton buttonWithType:UIButtonTypeDetailDisclosure];
}
return anView;
}

Thursday, July 8, 2010

pasing string value

statement "SELECT * FROM wateat_tbl where name like '%love%' or desc like '%love%'"
mixing SQL qurey + user input in one string

NSString* SQL_statement = [NSString stringWithFormat:@"SELECT * FROM wateat_tbl where name like '%%%@%%' or desc like '%%%@%%'", myStringPrt2, myStringPrt2];

const char *sqlStatement = [SQL_statement UTF8String]; // string to char need UTF8

Thursday, July 1, 2010

add images to nav bar

UIImage *image = [UIImage imageNamed: @"Enjoy TopBar1.png"];
UIImageView *imageView = [[UIImageView alloc] initWithImage: image];

self.navigationItem.titleView = imageView;

FEEDJIT Live