잡담소장소
iOS 초보 개발기 2 ( collection view controller ) 본문
xcode GM버전을 받고 (iOS개발자 남편 짱짱ㅋ_ㅋ)
playground에서 swift공부하다가 iOS앱 개발 관련해서 어제 배운거 리마인드용 기록
xcode GM은 프로젝트 생성시 language를 Swift나 Object-C를 선택하는 부분이 추가되어 있었다
처음 프로젝트 생성 후 가장 먼저 했던 것은
AppDelegate.m파일에 RootViewController를 세팅하는 것이었다
- (BOOL) application:(UIApplication *)application didFinishLaunchingWithOptions: ... { .... self.window.rootViewController = [[RootViewController alloc] init]; return YES; }
Deployment Target이 8.0이면 LaunchScreen이 자동으로 나오게 되는데
7.0으로 바꾸니 나오지 않았다
못써먹겠구만--;;;
구현하고자 하는 모델은 컬렉션을 선택했을 때 Single View가 나오도록 하는 것
CollectionViewController를 생성하고 그에 따른 CollectionViewCell도 생성한다
Storyboard를 이용하지 않았기 때문에 파일 생성시 xib도 생성해 주었다
RootViewController.m에 CollectionViewController를 메모리 할당하고
UINavigationController도 생성하여 자신의 RootViewController를 Collection View Controller로 설정한다
-(void) viewDidLoad{ .... CollectionViewController* colVC = [[CollectionViewController alloc] init]; UINavigationController* navVC = [[UINavigationController alloc] initWithRootViewController:colVC]; [self addChildViewController:navVC]; [self.view addSubView:navVC.view]; [navVC didMoveToParentViewController:self]; }
CollectionViewController.m에는 반드시 만들어줘야하는 함수가 있는데
섹션당 아이템의 갯수를 반환하는 numberOfItemsInSection과
셀의 정보를 반환해주는 담고 있는 cellForItemAtIndexPath이다
... -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger) section{ .... return 1; } -(UICollectionViewCell*) collectionView:(UICollectionView *) collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ CollectionViewCell* cell = [self.collectionView dequeueReusableCellWithReuseIdentifier:@"CollectionViewCell" for IndexPath:indexPath]; ... return cell; } //셀을 선택했을 때의 이벤트 -(void)collectionView:(UICollectionView*) collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{ ViewController1* vc1 = [[ViewController1 alloc] init]; [self.navigationController pushViewController:vc1 animated:YES]; }
CollectionViewController.xib에서 File's Owner를 선택한 후
오른쪽 탭의 3번째 아이콘을 클릭해서 Custom Class에 같이 생성한 파일명을 넣어주면
소스보기할 때 자동으로 그 파일을 열어준다
View->Collection View를 선택 후 File's Owner로 Function키를 누른채로 끌어다 놓으며
dataSource와 delegate를 설정하면 따로 코드에서 설정해줄 필요가 없다
(코드에 따라 그때그때 달라지긴 하겠지만)
'Study ;3' 카테고리의 다른 글
javascript에서 엑셀파일 생성하여 다운로드하기 + server side(PHP) (0) | 2014.10.28 |
---|---|
jQuery File Upload Plugin (blueimp) 적용삽질기 (1) | 2014.10.01 |
Swift Programming Language Experiment (0) | 2014.09.05 |
JAVA 설치 in MAC (0) | 2014.08.04 |
PHP mail 함수 사용하여 html 메일을 보낼 때 (0) | 2014.07.31 |