Archive for May 21st, 2010

Programming in Objective-C: Q&A

May 21, 2010

Q: How to vertically centre-align the text in textField?
A: [textField setContentVerticalAlignment:UIControlContentVerticalAlignmentCenter];

Q: How to make a dialogue window (i.e. add textFields) with AlertView?
A:
UIAlertView *describeWP = [[UIAlertView alloc] initWithTitle:@"Add a Waypoint" message:@"\n\n\n\n" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Done", nil];
UITextField *wpName = [[UITextField alloc] initWithFrame:CGRectMake(42, 45, 188, 25)];
[wpName setBackgroundColor:[UIColor whiteColor]];
[wpName setPlaceholder:@"Name your waypoint"];
[describeWP addSubview:wpName];
UITextField *wpDescrip = [[UITextField alloc] initWithFrame:CGRectMake(12, 80, 260, 55)];
[wpDescrip setBackgroundColor:[UIColor whiteColor]];
[wpDescrip setPlaceholder:@"Talk about it, e.g. tips, feeling, why excited ..."];
[describeWP addSubview:wpDescrip]
CGAffineTransform moveUp = CGAffineTransformMakeTranslation(0, 90);
[describeWP setTransform:moveUp];
[describeWP show];
[describeWP release];
[wpName release];
[wpDescrip release];

Q: Error: “missing required architecture i386 in file” for each framework.
A: Delete the following line from the project.pbxproj file:
FRAMEWORK_SEARCH_PATHS = ("$(inherited)", "\"$(DEVELOPER_DIR)/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.1.3.sdk/System/Library/Frameworks\"", );

Q: How to detect the zooming level after the user finger-changed it and let the map keep the level?
A:

Q: When using mapView.showsUserLocation=YES; the error says:

[MKUserLocation annotationType]: unrecognized selector sent to instance

… What is wrong?
A: Put the line: if ([annotation isKindOfClass:MKUserLocation.class]) return nil; in the MKAnnotationView method, then it is fine.
Read the rest of this entry »