[아이폰 앱 개발] 모달뷰를 View에 넣는 소스 와 Navigation 에 올리는 소스

네비게이션based 컨트롤러상에서 모달뷰

[self.navigationController presentModalViewController:self.cityWeatherNavigationController animated:YES];


ViewBased컨트롤러상에서의 모달뷰

[self presentModalViewController:self.cityWeatherNavigationController animated:YES];



http://www.iphonedevsdk.com/forum/iphone-sdk-development/21556-presentmodalviewcontroller-viewdidload.html

Posted by 오늘마감
[아이폰 앱 개발] navigatioBar 색상 과 모달뷰에서 프레임위치 크기조절하는 소스

CGRect framee = self.view.frame;

self.view.frame = CGRectMake(framee.origin.x, framee.origin.y+10, framee.size.width, framee.size.height);

cityWeatherNavigationController.navigationBar.tintColor = [UIColor darkGrayColor];

[self presentModalViewController:self.cityWeatherNavigationController animated:YES];

Posted by 오늘마감
Timer를 이용해서 재귀 반복 하는 소스

- (void)makeMyProgressBarMoving {

float actual = [threadProgressViewprogress];

threadValueLabel.text = [NSString stringWithFormat:@"%.2f", actual];

if (actual < 1) {

threadProgressView.progress = actual + 0.01;

[NSTimerscheduledTimerWithTimeInterval:0.5target:self

                         selector:@selector(makeMyProgressBarMoving) userInfo:nilrepeats:NO];

}

elsethreadStartButton.hidden = NO;

}

아이폰 어플 개발할때, timer를 이용해서 재귀호출하는 방법이다.

위의 함수는 progress Bar의 막대를 채우는 것으로, 재귀호출되면서 값이 증가되도록한다.

makeMyProgressBarMoving함수가 타이머가 0.5간격으로 울릴때, 다시 자신을 호출하며

0부터 0.01이 호출될때마다 더해져서 1이 되기전까지 계속된다.

재귀호출 중단점은 progress값이>1되면 중단된다.

Posted by 오늘마감
아이폰 어플개발할때 Wifi,3G연결 체크하는 소스

Usage is really simple:

  1. if ([Connection isConnected]) {  ...  }  
  2. else {  ...  }  

Connection.m file:

  1. //
  2. //  Connection.m
  3. //  iBlog
  4. //
  5. //  Created by Ondrej Rafaj on 12.11.09.
  6. //  Copyright 2009 Home. All rights reserved.
  7. //
  8. #import "Connection.h"
  9. @implementation Connection  
  10. + (BOOL) isConnected {  
  11.     // Create zero addy
  12.     struct sockaddr_in zeroAddress;  
  13.     bzero(&zeroAddress, sizeof(zeroAddress));  
  14.     zeroAddress.sin_len = sizeof(zeroAddress);  
  15.     zeroAddress.sin_family = AF_INET;  
  16.     // Recover reachability flags
  17.     SCNetworkReachabilityRef defaultRouteReachability = SCNetworkReachabilityCreateWithAddress(NULL, (struct sockaddr *)&zeroAddress);  
  18.     SCNetworkReachabilityFlags flags;  
  19.     BOOL didRetrieveFlags = SCNetworkReachabilityGetFlags(defaultRouteReachability, &flags);  
  20.     CFRelease(defaultRouteReachability);  
  21.     if (!didRetrieveFlags) {  
  22.         NSLog(@"Error. Could not recover network reachability flags");  
  23.         return NO;  
  24.     }  
  25.     BOOL isReachable = flags & kSCNetworkFlagsReachable;  
  26.     BOOL needsConnection = flags & kSCNetworkFlagsConnectionRequired;  
  27.     BOOL nonWiFi = flags & kSCNetworkReachabilityFlagsTransientConnection;  
  28.     NSURL *testURL = [NSURL URLWithString:@"http://www.google.com/"];  
  29.     NSURLRequest *testRequest = [NSURLRequest requestWithURL:testURL  cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:20.0];  
  30.     NSURLConnection *testConnection = [[[NSURLConnection alloc] initWithRequest:testRequest delegate:self] autorelease];  
  31.     return ((isReachable && !needsConnection) || nonWiFi) ? (testConnection ? YES : NO) : NO;  
  32. }  
  33. @end  

And this is the header Connection.h file:

  1. //
  2. //  Connection.h
  3. //  iBlog
  4. // 
  5. //  Created by Ondrej Rafaj on 12.11.09.
  6. //  Copyright 2009 Home. All rights reserved.
  7. //
  8. #import 
  9. #import 
  10. #import 
  11. #import 
  12. #import 
  13. @interface Connection : NSObject {  
  14. }  
  15. + (BOOL) isConnected;  
  16. @end  

And don't forget to include all the necessary frameworks ;) ... SystemConfiguration and libz.1.1.3.dylib

Ondrej Rafaj

Independent iPhone developer @ ondrej-rafaj.co.uk

I am available to give you a free quote or start working on your project ... just give me a call or drop a line. Please find all my details on my portfolio site ondrej-rafaj.co.uk

http://www.xprogress.com/post-40-iphone-internet-connection-check-wifi-3g-edge-something-like-reachability-h/

Posted by 오늘마감
개발할때 참조할 NSString 기본적인 소스

//기본 스트링 작업

#import
#import
#import

int main (int argc, char *argv[])
{
NSAutoreleasePool *Pool = [[NSAutoreleasePool alloc] init];
NSString *str1 = @"This is string A";
NSString *str2 = @"This is string B";
NSString *res;
NSComparisonResult compareResult;

//문자 개수 세기
NSLog (@"Length of str1 : %lu", [str1 length]);

//스트링 복사하기
res = [NSString stringWithString : str2];
NSLog (@"Concatentation : %@", str2);

//두 개의 스트링이 같은지 비교
if ([str1 isEqualToString : res] == YES)
NSLog(@"str1 == res");
else
NSLog(@"str1 != res");

//두 개의 스트링 크기 비교
compareResult = [str1 compare : str2];

if (compareResult == NSOrderedAscending)
NSLog (@"str1 < str2");
else if (compareResult == NSOrderedSame)
NSLog (@"str1 == str2");
else    //NSOrderedDescending
NSLog (@"str1 > str2");

//대문자로 변환
res = [str1 uppercaseString];
NSLog (@"Uppercase conversion : %s", [res UTF8String]);

//소문자로 변환
res = [str1 lowercaseString];
NSLog (@"Lowercase conversion : %@", res);
NSLog (@"Original string : %s", str1);

[pool drain];
return 0;

}



출처 : http://blog.naver.com/PostList.nhn?blogId=hana_815¤tPage=60
Posted by 오늘마감
개발할때 유용한 NSArray 기본적인 소스

#import

#import
#import
#import

int main (int argc, char *argv[])
{
int i;
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

//매월의 이름을 담고 있는 배열
NSArray *monthNames = [NSArray arrayWithObjects :
@"January", @"February", @"March", @"April",
@"May", @"June", @"July", @"August", @"September",
@"October", @"November", @"December", nil];

//배열 안의 모든 원소를 나열한다.
NSLog (@"Month Name");
NSLog (@"==== ====");

for (i = 0;; i < 12; ++i)
NSLog (@"%2i   %@", i + 1, [monthNames objectAtIndex : i]);

[pool drain];
return 0;

}



출처 : http://blog.naver.com/PostList.nhn?blogId=hana_815¤tPage=58
Posted by 오늘마감
참조할 NSMutableArray 기본적인 소스

#import

#import
#import
#import
#import

#define MAXPRIME 50

int main (int argc, char *argv[])
{
int i, p, prevPrime;
BOOL isPrime;
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

// 소수를 저장할 배열 생성
NSMutableArray *primes = 
[NSMutableArray arrayWithCapacity : 20];

//첫 소수 둘을 배열에 저장한다.
[primes addObject : [NSNumber numberWithInteger : 2]];
[primes addObject : [NSNumber numberWithInteger : 3]];

// 남은 소수 계산
for (p = 5; p <= MAXPRIME; p += 2) {
// p가 소수인지 검사한다.
isPrime = YES;

i = 1;

do{
prevPrime = [[primes objectAtIndex : i] integerValue];

if (p % prevPrime == 0)
isPrime = NO;
++i;
}while ( isPrime == YES && p / prevPrime >= prevPrime );

if (isPrime)
[primes addObject : [NSNumber numberWithInteger : p ]];
}

//결과를 표시한다.
for (i = 0; i < [primes count]; ++i)
NSLog (@"%li", (long) [[primes objectAtIndex : i] integerValue]);

[pool drain];
return 0;
}


출처 : http://blog.naver.com/PostList.nhn?blogId=hana_815¤tPage=57
Posted by 오늘마감
아이폰 UITextField 키보드 핸들링 소스

iPhone UITextField Tutorial: Handling Keyboard Interactions

This post is written to provide you with the process to get the return button working on the keypad that pops up while filling a text field, the “Background Tap” functionality, and also what to do when the text field hides behind the keypad.

First we make a demo View-based Application for this, say “BackgroundTapForBlog” .
Add a text field to BackgroundTapForBlogViewController.xib, declare it in your BackgroundTapForBlogViewController.h file ,say tfUsername and link them in .xib.

Return Button on KeyPad:

Once you are done with this, add a function “textFieldDoneEditing” to the BackgroundTapForBlogViewController.m file, and do not forget to declare it in the BackgroundTapForBlogViewController.h file. This function gets rid of the keypad once you are done filling in the textfield.

BackgroundTapForBlogViewController.h file -

1 #import
2 @interface BackgroundTapForBlogViewController: UIViewController{
3 UITextField *tfUsername;
4 }
5 @property(nonatomic, retain) IBOutlet UITextField *tfUsername;
6 -(IBAction) textFieldDoneEditing : (id) sender;
7 -(IBAction) backgroundTap:(id) sender;
8 @end

BackgroundTapForBlogViewController.m file -

01 #import "BackgroundTapForBlogViewController.h"
02  
03 @implementation BackgroundTapForBlogViewController
04 @synthesize tfUsername;
05  
06 - (void)viewDidUnload {
07 self.tfUsername = nil;
08 }
09  
10 - (void)dealloc {
11 [tfUsername release];
12 [super dealloc];
13 }
14  
15 -(IBAction) textFieldDoneEditing : (id) sender{
16 [sender resignFirstResponder];
17 }
18  
19 -(IBAction) backgroundTap:(id) sender{
20 [self.tfUsername resignFirstResponder];
21 }
22 @end

You can download the source code from here.

http://www.mobisoftinfotech.com/blog/iphone/iphone-uitextfield-tutorial-handling-keyboard-interactions/http://www.mobisoftinfotech.com/blog/iphone/iphone-uitextfield-tutorial-handling-keyboard-interactions/

Posted by 오늘마감
아이폰 어플에서 팝업 창 띄우는 소스


UIAlertView *popup = [[UIAlertView alloc] initWithTitle:@"haejin" message:@"ddd" delegate:nil cancelButtonTitle:@"close" otherButtonTitles:nil];   
[popup show];
 [popup release];

Posted by 오늘마감
아이폰 개발할때 sqlite3의 테이블 동적 변경하는 소스

- (id)initWithPrimaryKey:(NSInteger)pk database:(sqlite3 *)db tableName:(NSString *)tn { if ( (self = [super init]) ) 
 { primaryKey = pk; database = db; tableName = tn; // Compile the query for retrieving travel bug data. See insertIntoDatabase: for more detail. if (init_statement == nil) { // Note the '?' at the end of the query. This is a parameter which can be replaced by a bound variable. // This is a great way to optimize because frequently used queries can be compiled once, then with each // use new variable values can be bound to placeholders. strInit = [NSString stringWithFormat:@"SELECT name FROM %@ WHERE pk=?", self.tableName]; const char *sql = [strInit UTF8String]; if (sqlite3_prepare_v2(database, sql, -1, &init_statement, NULL) != SQLITE_OK) { NSAssert1(0, @"Error: failed to prepare statement with message '%s'.", sqlite3_errmsg(database)); } } // For this query, we bind the primary key to the first (and only) placeholder in the statement. // Note that the parameters are numbered from 1, not from 0. sqlite3_bind_int(init_statement, 1, primaryKey); if (sqlite3_step(init_statement) == SQLITE_ROW) { self.name = [NSString stringWithUTF8String:(char *)sqlite3_column_text(init_statement, 0)]; } else { self.name = @"Unknown"; } // Reset the statement for future reuse. sqlite3_reset(init_statement); dirty = NO;
 } return self; }



출처 : http://blog.naver.com/PostList.nhn?blogId=philipousys¤tPage=18
Posted by 오늘마감

티스토리 툴바