Skip to content

Instantly share code, notes, and snippets.

View edwardinubuntu's full-sized avatar

Edward Chiang edwardinubuntu

View GitHub Profile
@edwardinubuntu
edwardinubuntu / gist:777833
Created January 13, 2011 13:06
advanceButton
UIBarButtonItem* advanceButton = [[[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemAction
target:self action:@selector(action:)] autorelease];
self.navigationItem.rightBarButtonItem = advanceButton;
@edwardinubuntu
edwardinubuntu / gist:777834
Created January 13, 2011 13:07
UIActionSheetDelegate method
#pragma mark -
#pragma mark UIActionSheetDelegate method
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:
(NSInteger)buttonIndex
{
[actionSheet release];
NSLog(@"User Pressed Button %d\n", buttonIndex + 1);
}
-(void)action: (UIBarButtonItem *) item
@edwardinubuntu
edwardinubuntu / gist:788032
Created January 20, 2011 15:07
mapView:viewForAnnotation:
- (MKAnnotationView *)mapView:(MKMapView *)theMapView
viewForAnnotation:(id <MKAnnotation>)annotation
{
// try to dequeue an existing pin view first
static NSString* ItemAnnotationIdentifier = @"itemAnnotationIdentifier";
MKPinAnnotationView* pinView = (MKPinAnnotationView *)
[_mapView dequeueReusableAnnotationViewWithIdentifier:
ItemAnnotationIdentifier];
if (!pinView)
{
@edwardinubuntu
edwardinubuntu / gist:823522
Created February 12, 2011 04:39
rubywarrior play_turn beginner
class Player
@started_to_rest = false
@user_turn = false
$health_min_live = 10
$health_max_live = 15
def play_turn(warrior)
# add your code here
@user_turn = false
@edwardinubuntu
edwardinubuntu / gist:824807
Created February 13, 2011 16:08
MKReverseGeocoderDelegate protocol
#import <MapKit/MapKit.h>
#import <CoreLocation/CoreLocation.h>
@interface CTLocationManager : NSObject <CLLocationManagerDelegate,
MKReverseGeocoderDelegate> {
// instand variables
}
// Other methods
@edwardinubuntu
edwardinubuntu / gist:824809
Created February 13, 2011 16:09
Make sure the user has moved, the reverse geocoder time is over a minute
// Make sure the user has moved,
// the reverse geocoder time is over a minute,
// or is the first time ask
if (isMoved
|| [self.lastReverseGeocoderTime timeIntervalSinceNow] < -60
|| !self.lastReverseGeocoderTime) {
// Start to ask the reverse geocoder service
self.reverseGeocoder = [[[MKReverseGeocoder alloc] initWithCoordinate:
self.currentLocation.coordinate] autorelease];
self.reverseGeocoder.delegate = self;
@edwardinubuntu
edwardinubuntu / gist:824810
Created February 13, 2011 16:11
didFailWithError didFindPlacemark
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder
didFailWithError:(NSError *)error
{
// Do something
}
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder
didFindPlacemark:(MKPlacemark *)placemark
{
self.placeName = placemark.thoroughfare;
@edwardinubuntu
edwardinubuntu / gist:833947
Created February 18, 2011 16:38
UIAlertViewDelegate
@interface MyViewController : UIViewController <UIAlertViewDelegate>
{
UIAlertView *baseAlert;
}
@end
@edwardinubuntu
edwardinubuntu / gist:833952
Created February 18, 2011 16:40
UIActivityIndicatorView
@implementation TestBedViewController
- (void) performDismiss
{
[baseAlert dismissWithClickedButtonIndex:0 animated:NO];
}
- (void) action: (UIBarButtonItem *) item
{
baseAlert = [[[UIAlertView alloc]
initWithTitle:@"Please Wait" message:nil
@edwardinubuntu
edwardinubuntu / gist:843910
Created February 25, 2011 15:08
more limit offset
if (!more) {
if ([self.items count] < INITIAL_DATA_NUMBER) {
self.limit = [NSNumber numberWithInt:INITIAL_DATA_NUMBER];
} else {
self.limit = [NSNumber numberWithInt:([self.items count])];
}
self.offset= [NSNumber numberWithInt:0];
[self.items removeAllObjects];
} else {
self.offset = [NSNumber numberWithInt: