NSMutableArray *imageArray = [[NSMutableArray alloc]init];

for (int i = 1; iy <= 40; i++) {
[imageArray addObject:[UIImage imageNamed:[NSString stringWithFormat:@"s%02i.png", i]]];
}

UIImageView * ryuJump = [[[UIImageView alloc] initWithFrame:
CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)]autorelease];
ryuJump.animationImages = imageArray;
ryuJump.animationDuration = 2.1;
ryuJump.contentMode = UIViewContentModeCenter;

[someview addSubview:ryuJump];

[ryuJump startAnimating];
[imageArray release];

-(NSString*)urlEncoded:(NSString*)str {

NSString *escapedUrlString = [str stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
return escapedUrlString;

}

-(NSString*)urlDecoded:(NSString*)str {

NSString *cleanUrlString = [str stringByReplacingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
return cleanUrlString;

}

NSString *devStr = @”http://localhost/dri/json?foo=#bar&something=true&miscc=Foo bar!”;

NSLog(@”devStr: %@”,devStr);

NSString *encString = [self urlEncoded:devStr];
NSLog(@”encString: %@”,encString);

NSString *decString = [self urlDecoded:encString];
NSLog(@”decString: %@”,decString);

UIImage *image = [UIImage imageNamed:@"greatimage.png"];
UIImageView *imgView = [[UIImageView alloc] initWithImage:image];
imgView.frame = CGRectMake(0, 0, 320, 90);
[self.view addSubview:imgView];
[imgView release];

// a button
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self action:@selector(targetMethod:) forControlEvents:UIControlEventTouchDown];
[button setTitle:@"Show View" forState:UIControlStateNormal];
button.frame = CGRectMake(0.0, 0.0, 160.0, 40.0);
[self.view addSubview:button];

////////////////////////////////////////
// Button with background images
////////////////////////////////////////

UIButton *bttn = [UIButton buttonWithType:UIButtonTypeCustom];
bttn.frame = CGRectMake(0, 200, 97, 38);
[bttn setTitle:@"Dev One" forState:UIControlStateNormal];
[bttn addTarget:self action:@selector(targetMethod:) forControlEvents:UIControlEventTouchUpInside];

UIImage *bttnImageNormal = [UIImage imageNamed:@"button.png"];
[bttn setImage:bttnImageNormal forState:UIControlStateNormal];

UIImage *bttnImageSelected = [UIImage imageNamed:@"button-selected.png"];
[bttn setImage:bttnImageSelected forState:UIControlStateHighlighted];

[self.view addSubview:bttn];

-(IBAction)targetMethod:(id)sender {

NSLog(@”targetMethod”);

}

#import <Foundation/Foundation.h>

@interface RemotePreferences : NSObject {
NSMutableData *incomingData;
}

@end

@implementation RemotePreferences

-(id)init {

self = [super init];

if (self) {

NSURL *url = [NSURL URLWithString: @"http://example.com/configs.plist"];
NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:30.0];
__unused NSURLConnection *fetchConn = [[[NSURLConnection alloc] initWithRequest:request delegate:self] autorelease];

}

return self;

}

- (void)connection:(NSURLConnection *)sender didReceiveData:(NSData *)data {

if (!incomingData) {
incomingData = [[NSMutableData alloc] init];
}

[incomingData appendData:data];

}

- (void)connectionDidFinishLoading:(NSURLConnection *)sender {

NSDictionary *prefsDict = [[[NSDictionary alloc] init] autorelease];
prefsDict = [NSPropertyListSerialization propertyListFromData:incomingData mutabilityOption:NSPropertyListImmutable format:nil errorDescription:nil];

[[NSUserDefaults standardUserDefaults] registerDefaults:prefsDict];

// NSLog(@"NSUserDefaults dump: %@", [[NSUserDefaults standardUserDefaults] dictionaryRepresentation]);

}

- (void)connection:(NSURLConnection *)sender didFailWithError:(NSError *)error {
NSLog(@"connection failed: %@", [error localizedDescription]);
}

-(void)dealloc {
FuncLog();

[super dealloc];

[incomingData release];
incomingData = nil;

}

//- (NSURLRequest *)connection:(NSURLConnection *)c willSendRequest:(NSURLRequest *)req redirectResponse:(NSURLResponse *)res {}
//- (void)connection:(NSURLConnection *)sender didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)ch {}
//- (NSCachedURLResponse *)connection:(NSURLConnection *)sender willCacheResponse:(NSCachedURLResponse *)cachedResponse{}

@end

self.tabBarController.selectedIndex = 3;
[self.tabBarController.selectedViewController viewDidAppear:YES];

if inside a custom tabbarcontroller doing this

//call viewWillDisappear in the current view
[self.selectedViewController viewWillDisappear:YES];

//change view
self.selectedIndex = tabID;

//call viewDidAppear in the current view
[self.selectedViewController viewDidAppear:YES];

Was not written to be used on a real timestamp, was written to be used counting up from 0.

int tmp = secondCount;

int _Days = tmp / (60 * 60 * 24);
tmp -= _Days * (60 * 60 * 24);
int _Hrs = tmp / (60 * 60);
tmp -= _Hrs * (60 * 60);
int _Min = tmp / 60;
tmp -= _Min * 60;
int _Sec = tmp;

NSString *displayString = [NSString stringWithFormat:@"%02i:%02i:%02i:%02i", _Days, _Hrs, _Min, _Sec];

-(void)callJavascriptFunctionInAllWebViews {

if ([[scrollView subviews] count] > 0) {

for (UIWebView *subWebView in [scrollView subviews]) {
NSString *jsCommand = [NSString stringWithFormat:@"whateverJSFunction();"];
[subWebView stringByEvaluatingJavaScriptFromString:jsCommand];
}

}

}

BOOL didItWork = [self createDirAndFile:@"index.html" inDir:@"somedirectory"];
NSLog(@”WAS FILE CREATED? %i”, didItWork);

// methods used

-(BOOL)createDirAndFile:(NSString*)fileName inDir:(NSString*)dir {

NSString *str = @”whatever needs to be in the file when created”;
NSData *data=[str dataUsingEncoding:NSUTF8StringEncoding];

NSFileManager *filemgr = [NSFileManager defaultManager];

NSString *documentsDirectoryPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSLog(@” documentsDirectoryPath = %@”, documentsDirectoryPath);

NSString *targetDir = [documentsDirectoryPath stringByAppendingPathComponent:dir];
NSLog(@” targetDir = %@”, targetDir);

NSString *targetFile = [targetDir stringByAppendingPathComponent:fileName];
NSLog(@” targetFile = %@”, targetFile);

BOOL isDir;

if (![filemgr fileExistsAtPath:targetDir isDirectory:&isDir]) {

NSLog(@”Directory did not exist so create it”);
[filemgr createDirectoryAtPath:targetDir withIntermediateDirectories:NO attributes:nil error:nil];

NSLog(@”If the target directory did not exist the file we are creating certainly did not exist so create it”);
return [self createMyFile:targetFile contents:data];

} else {

return [self createMyFile:targetFile contents:data];

}

}

-(BOOL) createMyFile:(NSString*)desiredFile contents:(NSData*)fileContents {

if ( ![[NSFileManager defaultManager] fileExistsAtPath:desiredFile] ) {

[[NSFileManager defaultManager] createFileAtPath:desiredFile contents:fileContents attributes:nil];
return YES;

}

return NO;

}

-(void)createHtmlFileIfMissing:(NSString*)fileName inDir:(NSString*)dir {

NSString *str= @”whatever needs to be there to start”;
NSData *data=[str dataUsingEncoding:NSUTF8StringEncoding];

NSFileManager *filemgr = [NSFileManager defaultManager];
NSString *documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];

NSString *targetDir = [documentsPath stringByAppendingPathComponent:dir];
NSString *targetFile = [targetDir stringByAppendingPathComponent:fileName];
BOOL targetFileExists = [[NSFileManager defaultManager] fileExistsAtPath:targetFile];

if (!targetFileExists ) {
[filemgr createFileAtPath:targetFile contents:data attributes:nil];
}

}

© 2012 James Border Suffusion theme by Sayontan Sinha