tableview 관련

컴퓨터/아이폰 : 2012. 11. 26. 00:50


http://j2enty.com/82


 -. TableView DataSource 메소드들

 DataSource Methods (9개)

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
 : 표현할 데이터의 총 Section의 갯수. (2차원 배열의 경우)

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
 : 표현할 데이터에서 하나의 Section에 있는 총 Row의 갯수. (1차원배열의 경우엔 Section이 아닌 Array에 들어있는 총 Object의 갯수)

- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
 : Section의 헤더 

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
 : Section의 풋터 

- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
 :  

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
 : 실제 하나의 셀마다에 값을 넣어주는 부분 

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
 : 삽입/삭제를 이용할지 안할지를 정의하는 부분 

- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
 : Row의 이동을 허용할지 안할지를 정의하는 부분 

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
 : 테이블뷰의 삽입/삭제 작업 후에 호출 됨

- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
 : 테이블뷰의 이동작업 후에 호출 됨 

 : 위의 메소드들 중 테이블뷰의 삽입/삭제/이동에 대한 설명은 후반부에 다시 다루겠습니다.

 2.2 TableView Delegate
  -. Delegate Methods

Delegate Methods (21개)

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
 : Footer 높이 

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
 : Header 높이 

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
 : Row 높이 
 

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
 : DataSource의 String형 헤더가 아닌 커스팀가능한 TableView Footer를 만들 때 사용 

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section

 : DataSource의 String형 헤더가 아닌 커스팀가능한 TableView Header를 만들 때 사용
 

- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
 : 테이블뷰의 Row를 클릭했을 때 호출 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
 : tableView:willSelectRowAtIndexPath가 호출 된 후 호출
 

- (NSIndexPath *)tableView:(UITableView *)tableView willDeselectRowAtIndexPath:(NSIndexPath *)indexPath
 : 테이블뷰의 선택을 해지할 때 호출 

- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
 : tableView:WillDeselectRowAtIndexPath가 호출 된 후 호출
 

- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
 : TableView Cell의 오른쪽에 붙는 AccessoryButton을 클릭했을 때 호출 

- (UITableViewCellAccessoryType)tableView:(UITableView *)tableView accessoryTypeForRowWithIndexPath:(NSIndexPath *)indexPath
 : Accessory의 종류를 변경할 때 사용
 

- (void)tableView:(UITableView *)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath
 : 테이블뷰의 수정을 시작할 때 호출 

- (void)tableView:(UITableView *)tableView didEndEditingRowAtIndexPath:(NSIndexPath *)indexPath
 : 테이블뷰의 수정을 종료할 때 호출
 
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
 : 테이블뷰의 EditStyle(삽입/삭제)에 대해서 정의할 때 사용 

- (BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath
 : 테이블뷰가 edit상태 일 때 Cell의 앞쪽에 들여쓰기를 사용할지 안할지를 정의할 때 사용 

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
 : 테이블뷰가 다 구성되고 사용자에게 보여지기 직전에 마지막으로 호출되는 메소드 


- (BOOL)tableView:(UITableView *)tableView canPerformAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender

- (void)tableView:(UITableView *)tableView performAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender


- (NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath

- (NSIndexPath *)tableView:(UITableView *)tableView targetIndexPathForMoveFromRowAtIndexPath:(NSIndexPath *)sourceIndexPath toProposedIndexPath:(NSIndexPath *)proposedDestinationIndexPath

- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath 


      
Posted by k_ben


제발 지우지 말기를;;;


http://algobomyun.tistory.com/131#.UKoPr7TDL5Y

'컴퓨터 > 아이폰' 카테고리의 다른 글

MRImageViewer -> 이미지 슬라이드 예제  (0) 2012.12.26
tableview 관련  (0) 2012.11.26
scrollView에서 터치 이벤트 받기  (0) 2012.10.14
맥os find 숨긴 파일 보이기 감추기  (0) 2012.05.18
THEOS iOS hooking 툴  (0) 2012.05.10
      
Posted by k_ben


기본적으로 UIView에서는

(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{

NSLog(@"Began");

}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{

NSLog(@"Ended");

}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{

NSLog(@"Moved");

}

- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event{

NSLog(@"Cancelled");

}


를 이용하여 터치 이벤트를 처리할 수 있습니다.
그러나 UIView에 ScrollView를 올려놓게 되면 터치 이벤트가 ScrollView에서 처리하기 때문에

상위 클래스인 UIView까지 전달되지 못합니다.
따라서 상위 클래스로 터치 이벤트를 넘겨주기 위해터치 이벤트를 상위 클래스로 넘겨주기 위해서
UIScrollView를 상속하여 터치 이벤트 메서드들을 오버라이딩해야 합니다.

1. 우선 우리가 원하는 터치 이벤트와 뷰, 스크롤 뷰가 들어있는 클래스와 XIB파일을 만듭니다.
제가 만든 파일명은 ViewController입니다.
<ViewConroller.h>

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController<UIScrollViewDelegate>{

UIScrollView* scrollView;

}

@property(nonatomic, strong) IBOutlet UIScrollView* scrollView;


@end

#import "ViewController.h"

@end

<ViewConroller.m>

#import "ViewController.h"


@implementation ViewController

@synthesize scrollView;

- (void)didReceiveMemoryWarning

{

[super didReceiveMemoryWarning];

// Release any cached data, images, etc that aren't in use.

}


#pragma mark - View lifecycle

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{

NSLog(@"Began");

}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{

NSLog(@"Ended");

}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{

NSLog(@"Moved");

}

- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event{

NSLog(@"Cancelled");

}


- (void)viewDidLoad

{

[super viewDidLoad];

// Do any additional setup after loading the view, typically from a nib.

UIImageView *modelImageView = [[UIImageView alloc]init];

modelImageView.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"MODEL_List.jpg" ofType:nil]];

modelImageView.frame = CGRectMake(0, 0, 320, 6700);

scrollView.contentSize = CGSizeMake(320, 6700);

modelImageView.userInteractionEnabled = YES;

[scrollView addSubview:modelImageView];

}


- (void)viewDidUnload

{

[super viewDidUnload];

// Release any retained subviews of the main view.

// e.g. self.myOutlet = nil;

}


- (void)viewWillAppear:(BOOL)animated

{

[super viewWillAppear:animated];

}


- (void)viewDidAppear:(BOOL)animated

{

[super viewDidAppear:animated];

}


- (void)viewWillDisappear:(BOOL)animated

{

[super viewWillDisappear:animated];

}


- (void)viewDidDisappear:(BOOL)animated

{

[super viewDidDisappear:animated];

}


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

{

// Return YES for supported orientations

return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);

}


@end


2. 그리고 ViewController.xib파일에는 한 개의 스크롤뷰가 들어있는 뷰가 있습니다.
그리고 뷰 안의 스크롤뷰는 ViewController.h에서 IBOutlet으로 선언한 scrollView와 연결해 줍니다.




3. 이제 UIScrollView를 상속받은 클래스를 새로 생성합니다. 이 클래스는 xib파일을 필요로 하지 않으므로 xib파일 생성은 하지 않습니다.
제가 이 클래스에게 원하는 것은 터치 이벤트를 상위로 전달하는 것뿐이므로 불필요한 소스들은 넣지 않았습니다.
제가 만든 클래스의 이름은 ModelScrollViewController입니다.

#import <UIKit/UIKit.h>


@interface ModelScrollViewController : UIScrollView


@end


#import "ModelScrollViewController.h"


@implementation ModelScrollViewController


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

{

return self;

}


- (void)didReceiveMemoryWarning

{

}


#pragma mark - View lifecycle

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{

[self.superview touchesBegan:touches withEvent:event];

}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{

[self.superview touchesEnded:touches withEvent:event];

}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{

[self.superview touchesMoved:touches withEvent:event];

}

- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event{

[self.superview touchesCancelled:touches withEvent:event];

}


- (void)viewDidUnload

{


}


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

{

// Return YES for supported orientations

return (interfaceOrientation == UIInterfaceOrientationPortrait);

}


@end


상위 클래스인 ViewController로 이벤트를 넘겨주기 위해서 를[self.superview touchesBegan:touches withEvent:event]를 사용하였습니다.

4. 이 마지막으로 다시 ViewController.xib파일로 가서 scrollView의 custom class를 변경해 주도록 합니다.

'컴퓨터 > 아이폰' 카테고리의 다른 글

tableview 관련  (0) 2012.11.26
iOS 버전 바꾸기  (0) 2012.11.19
맥os find 숨긴 파일 보이기 감추기  (0) 2012.05.18
THEOS iOS hooking 툴  (0) 2012.05.10
엔터프라이즈 계정 in house 배포 방식..  (0) 2012.02.15
      
Posted by k_ben


터미널에서 아래 명령어를 실행

defaults write com.apple.Finder AppleShowAllFiles YES


실행 후 파인더(Finder) 재실행을 하면


숨김파일이 보인다.
반대로 숨김파일을 다시 안 보려면 아래의 명령어를 실행한 후 파인더(Finder) 재시작

defaults write com.apple.Finder AppleShowAllFiles NO

'컴퓨터 > 아이폰' 카테고리의 다른 글

iOS 버전 바꾸기  (0) 2012.11.19
scrollView에서 터치 이벤트 받기  (0) 2012.10.14
THEOS iOS hooking 툴  (0) 2012.05.10
엔터프라이즈 계정 in house 배포 방식..  (0) 2012.02.15
pc에서 iphone 제어  (0) 2012.01.31
      
Posted by k_ben


1. 다음 정보를 환경 정보 파일에 추가하자.
export THEOS=/opt/theos
당장 작업해야하니 일단 터미널에서 한번 저걸 실행해주면 좋겠지.
(MacPorts 사용 시 /opt 폴더는 root 권한이 필요하므로 다른 곳으로 옮기던가, theos 만 권한 설정을 한다던가 하도록 한다.)

2. THEOS 본체를 받자.
서브버전 이용 시,
svn co http://svn.howett.net/svn/theos/trunk $THEOS
git 이용 시,
git clone git://github.com/DHowett/theos.git $THEOS


git clone git://github.com/rpetrich/theos.git $THEOS

3. ldid를 받자.
curl -s http://dl.dropbox.com/u/3157793/ldid > $THEOS/bin/ldid; chmod +x $THEOS/bin/ldid

4. 설치해둔 iOS SDK 버전을 환경 정보에 추가한다.
3.0이면 안 해도 된다.
SDKVERSION=4.2

5. include를 추가.
https://github.com/rpetrich/iphoneheaders
에서 받아서 $THEOS/include 아래에 옮겨둔다.
아마도,
git clone git://github.com/rpetrich/iphoneheaders.git $THEOS/include
하면 걍 되지 않을까 싶은데 안 해봐서 모르겠네. ㅋ


cd $THEOS
./git-submodule-recur.sh init

6. include 중 빠진 것을 채워넣자.
include 아래에 폴더 하나씩 살펴보면, 간혹가다가 readme 파일들이 보일텐데,
저작권 문제로 배포를 못 하는 파일들을, 구하는 방법 및 패치 내용 등등을 적어둔 것이다.
보고 그대로 넣으면 된다.




프로젝트를 만드는 방법:


터미널에서, 만들 위치로 이동 후
$THEOS/bin/nic.pl

를 실행하면 마법사가 나타난다.
알맞게 선택하면 알아서 만들어 주니까 잘 쓰도록 하자.

'컴퓨터 > 아이폰' 카테고리의 다른 글

scrollView에서 터치 이벤트 받기  (0) 2012.10.14
맥os find 숨긴 파일 보이기 감추기  (0) 2012.05.18
엔터프라이즈 계정 in house 배포 방식..  (0) 2012.02.15
pc에서 iphone 제어  (0) 2012.01.31
MDM에 관한거...  (0) 2012.01.20
      
Posted by k_ben


xcode에서 archive로 빌드
빌드가 완료 되면
organizer의 archives에 등록할 앱이 보임
그럼 Share Application 클릭


save for enterprise distribution 체크 박스 클릭 



application URL은 서버에 저장 될 파일 위치의 주소
 

 
 이렇게 진행 후
저장을 누르면 저장한 곳에 *.ipa파일과 *.plist파일이 생성
그 두 파일을 배포서버에 복사 

그 다음 html 파일을 하나 생성
*.html 파일 생성 후

<a href="itms-services://?action=download-manifest&url=http://192.168.0.11/test.plist">프로그램 설치</a>
 
이 소스 내용 추가

그리고 이 html을 아이폰에서 불러오면 끝.. 
////////////////////////

모든 것이 이ㅅ상이 없음에도 설치가 안된다면...

웹서버에서 MIME Type을 등록한다.

 

ipa      application/octet-stream

plist    text/xml

 

다음은 톰캣에서 등록한 예...

- <mime-mapping>
  <extension>ipa</extension>
  <mime-type>application/octet-stream</mime-type>
  </mime-mapping>
- <mime-mapping>
  <extension>plist</extension>
  <mime-type>text/xml</mime-type>
  </mime-mapping> 

'컴퓨터 > 아이폰' 카테고리의 다른 글

맥os find 숨긴 파일 보이기 감추기  (0) 2012.05.18
THEOS iOS hooking 툴  (0) 2012.05.10
pc에서 iphone 제어  (0) 2012.01.31
MDM에 관한거...  (0) 2012.01.20
화면 이동시 에니메이션 효과  (0) 2012.01.18
      
Posted by k_ben


PC에서 iPhone 제어에는 
iPhone 에서는 Veency, PC에서는 Ultra VNC가 필요합니다.




iPhone에서 Veency 설치 방법은 아래와 같습니다.
[1] Cydia 로 들어간다
[2] 화면 아래쪽에서 Search 메뉴를 선택하세요
[3] "Package Names & Descriptions" 가 써있는 입력란에 Veency라고 입력하고 Search 버튼을 누릅니다.
[4] 검색결과에서 Veency를 선택하면 나오는 화면에서 Install 버튼 터치 -> Confirm 버튼 터치
[5] 조금만 기다리면 설치가 완료됩니다.




PC에서 Ultra VNC를 설치하는 방법은 다음과 같습니다.
[1] Ultra VNC 를 다운로드 받습니다.
(프리웨어이며, 네이버에서 검색하면 쉽게 다운로드 받을 수 있습니다.)
[2] 다운로드받은 파일을 설치합니다. 
     딱히 설정해 줄 옵션은 없으므로 그냥 Next > Next... 이런식으로 설치하시면 됩니다.


 PC에서 iPhone을 원격 제어하기 전에 다음의 사항들을 확인해 주세요
[1] iPhone이 해킹이 되어 있는지
[2] 와이파이(인터넷 연결)이 활성화 되어 있는지
[3] iPhone에 Veency를 설치 했는지.


 PC에서 iPhone 원격 제어 방법은 아래와 같습니다.
[1] iPhone 설정에 들어가서
[2] Wi-Fi 선택 
[3] 현재 연결된 wi-fi 네트워크에서 > 버튼을 터치
[4] IP 주소를 확인할 수 있습니다. 여기 나온 아이피 주소를 알아두세요.
[5] PC에서 UltraVNC Viewer를 실행합니다.
[6] VNC Server : 입력란에 방금전 알아두었던 아이폰의 아이피 주소를 입력해주세요
     (예 : 192.158.46.24:5900) <= 포트번호는 이대로 적어주세요.
[7] Ultra VNC Viewer에서 Connect 버튼을 누릅니다.
[8] iPhone에 Remote Access Request 창이 뜰 것입니다. Accept를 눌러주세요
[9] PC 화면에 iPhone 창이 뜹니다. PC의 아이폰 화면에서 드래그를 해보면 아이폰에서 똑같이 움직이게 됩니다.
[10] iPhone 원격제어 완료입니다 

'컴퓨터 > 아이폰' 카테고리의 다른 글

THEOS iOS hooking 툴  (0) 2012.05.10
엔터프라이즈 계정 in house 배포 방식..  (0) 2012.02.15
MDM에 관한거...  (0) 2012.01.20
화면 이동시 에니메이션 효과  (0) 2012.01.18
두개 클래스 사용 예제 소스  (0) 2012.01.18
      
Posted by k_ben


음 예를 들어서 DeviceLock에 대해서 말씀 드리자면 
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
    <dict>
        <key>Command</key>
        <dict>
            <key>RequestType</key>
            <string>DeviceLock</string>
        </dict>
        <key>CommandUUID</key>
        <string>1234</string>
    </dict>
</plist>
위와 같은 메세지를 특정 사용자 아이폰(정책이 설치되어 있는)에 보내면 
메세지를 수신받은 아이폰은 사용자가 사용중이였다고 하더라도 저 메세지를 받은 순간에 아이폰이 잠기게 됩니다. 
위와 같은 문서를 정의해 놓은 것은 Apple에서 말하는 MDM API 입니다. 

카메라는 명령에 의한 것은 아니고 정책에 의해 관리 되게 됩니다. 
카메라를 못쓰게 하고 싶으시면 명령을 내리는 것이 아니라 정책을 업데이트 하던가 해야 하는 것이지요. 
위에서 말한 정책은 기본적으로는 iPhone Configuration Utility로 만들수 있습니다. 
MDM까지 하게 되면 조금 복잡해 지고요. ^^

'컴퓨터 > 아이폰' 카테고리의 다른 글

엔터프라이즈 계정 in house 배포 방식..  (0) 2012.02.15
pc에서 iphone 제어  (0) 2012.01.31
화면 이동시 에니메이션 효과  (0) 2012.01.18
두개 클래스 사용 예제 소스  (0) 2012.01.18
계산기 소스  (0) 2012.01.18
      
Posted by k_ben


- (void) showURL:(NSURL *)address withTitle:(NSString *)title {

    


>>>>>>>>>>>> 아래 소스 추가  >>>>>>>

UIViewAnimationTransitionCurlUp : 에니메이션 유형


    [UIView beginAnimations:nil context:NULL];

    [UIView setAnimationDuration:1.5]; 지연시간

    [UIView setAnimationBeginsFromCurrentState:YES]; 현재창인지

    [UIView setAnimationTransition:UIViewAnimationTransitionCurlUpforView:self.navigationController.view cache:NO]; 유형, 대상, 겹치기 

    [UIView commitAnimations];


>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

    

    

webView *vc = [[webView allocinitWithNibName:@"webView" bundle:nil];

vc.title =  title;

vc.webUrl = address;

[self.navigationController pushViewController:vc animated:YES];

[vc release];

}

'컴퓨터 > 아이폰' 카테고리의 다른 글

pc에서 iphone 제어  (0) 2012.01.31
MDM에 관한거...  (0) 2012.01.20
두개 클래스 사용 예제 소스  (0) 2012.01.18
계산기 소스  (0) 2012.01.18
날짜 -> 시간 시간->날짜 변환  (0) 2012.01.18
      
Posted by k_ben


//

//  AddressCard.h


#import <Foundation/NSObject.h>


@interface AddressCard : NSObject {

NSString *name;

NSString *email;

NSString *address;

NSString *phone;

NSString *job;

}


@property (copy) NSString *name, *email, *address, *phone, *job;

-(void) disp;

@end


//

//  AddressCard.m


#import "AddressCard.h"


@implementation AddressCard


@synthesize name, email, address, phone, job;


-(void) disp{

NSLog(@"%@\t %@\t %@\t %@\t %@",nameemailaddressphonejob);

}

@end


//

//  AddressBook.h


#import <Foundation/NSArray.h>

#import "AddressCard.h"


@interface AddressBook : NSObject {


NSMutableArray *book;

}

-(AddressBook *) initWith;

-(void) addCard: (AddressCard *) theCard;

-(void) list;

-(int) countCard;

-(void) removeCard : (AddressBook *) theCard;

-(AddressCard *) lookup: (NSString *) theName;

-(void) dealloc;


@end



//

//  AddressBook.m


#import "AddressBook.h"


@implementation AddressBook


// 초기화 

-(AddressBook *) initWith{

self = [super init]; // 필수 요소

if(self){

book = [[NSMutableArray allocinit];

}

return self// 반드시 self 리턴

}


-(void) addCard: (AddressCard *) theCard{

[book addObject:theCard];

}


-(void) list{

for(AddressCard *i in book){

[i disp];

}

}


-(int) countCard{

return [book count];

}


-(void) removeCard : (AddressBook *) theCard{ // theCard = card1

[book removeObjectIdenticalTo:theCard];

}


-(AddressCard *) lookup: (NSString *) theName{

for(AddressCard *i in book){

if ([[i namecompare:theName] == NSOrderedSame) {

return i;

}

}

return nil;

}


-(void) dealloc{

[book release];

[super dealloc];

}


@end


///////////////////////////////



#import <Foundation/NSAutoreleasePool.h>

//#import <Foundation/NSArray.h>


#import "AddressBook.h"

#import "AddressCard.h"


int main (int argc, const char * argv[]) {

    NSAutoreleasePool * pool = [[NSAutoreleasePool allocinit];


AddressCard *card1 = [[AddressCard allocinit];

AddressCard *card2 = [[AddressCard allocinit];

AddressCard *card3 = [[AddressCard allocinit];

AddressCard *card4 = [[AddressCard allocinit];

[card1 setName:@"정성덕"];

[card1 setEmail:@"holy@dot.com"];

[card1 setAddress:@"address1"];

[card1 setPhone:@"111"];

[card1 setJob:@"programmer"];

[card2 setName:@"이성아"];

[card2 setEmail:@"lee@dot.com"];

[card2 setAddress:@"address2"];

[card2 setPhone:@"222"];

[card2 setJob:@"prog2"];

[card3 setName:@"정시온"];

[card3 setEmail:@"sion@dot.com"];

[card3 setAddress:@"address3"];

[card3 setPhone:@"333"];

[card3 setJob:@"prog3"];

[card4 setName:@"정시아"];

[card4 setEmail:@"sia@dot.com"];

[card4 setAddress:@"address4"];

[card4 setPhone:@"444"];

[card4 setJob:@"progr4"];

//[card1 disp];


AddressBook *book = [[AddressBook allocinitWith]; 


[book addCard:card1];

[book addCard:card2];

[book addCard:card3];

[book addCard:card4];

 

[book list];

NSLog(@"인원수 : %i" , [book countCard]);

//NSLog(@"인원수 : %i" , [book count]); //  안되는 이유는 ??

//여기서의 book 클래스가 AddressBook이므로 배열의 메서드인 count 사용하지 

                //못한다

// AddressBook 정체는 AddressCard 배열처럼 담아서 배열이 아닌 객체지만 

                // 배열처럼 쓰려고 한다하지만 배열의 메소드는 바로 쓸수 없어서AddressBook 

                // 클래스안에서 해결


[book removeCard : card1];

//[book removeObjectIdenticalTo:card1];

[book list];

if ([book lookup:@"정시아"] != nil)

NSLog(@"찾았습니다.");

else

NSLog(@"찾지 못했습니다.");

[card1 release];

[card2 release];

[card3 release];

[card4 release];

[book release];

    [pool drain];

    return 0;

}


////////////////////////

2011-05-25 11:17:18.465 test54[3721:a0f] 정성덕  holy@dot.com  address1  111 programmer

2011-05-25 11:17:18.467 test54[3721:a0f] 이성아  lee@dot.com  address2  222  prog2

2011-05-25 11:17:18.468 test54[3721:a0f] 정시온  sion@dot.com  address3  333  prog3

2011-05-25 11:17:18.468 test54[3721:a0f] 정시아  sia@dot.com  address4  444  progr4

2011-05-25 11:17:18.468 test54[3721:a0f] 인원수 : 4

2011-05-25 11:17:18.469 test54[3721:a0f] 이성아  lee@dot.com  address2  222  prog2

2011-05-25 11:17:18.469 test54[3721:a0f] 정시온  sion@dot.com  address3  333  prog3

2011-05-25 11:17:18.470 test54[3721:a0f] 정시아  sia@dot.com  address4  444  progr4

2011-05-25 11:17:18.470 test54[3721:a0f] 찾았습니다.

'컴퓨터 > 아이폰' 카테고리의 다른 글

MDM에 관한거...  (0) 2012.01.20
화면 이동시 에니메이션 효과  (0) 2012.01.18
계산기 소스  (0) 2012.01.18
날짜 -> 시간 시간->날짜 변환  (0) 2012.01.18
파일 관련 자료  (0) 2012.01.18
      
Posted by k_ben