본문 바로가기
  • SDXL 1.0 + 한복 LoRA
  • SDXL 1.0 + 한복 LoRA
Development/iPhone

[옛 글] SimpleSectionedTableView - RootViewController

by 마즈다 2013. 7. 16.
반응형

최초 작성일 : 2010/04/17 04:21



RootViewController.h


@interface RootViewController : UITableViewController {

NSArray *regions;

}

//지역 객체를 담을 배열 선언

@property (nonatomicretain) NSArray *regions;


@end



RootViewController.m


#import "RootViewController.h"

#import "SimpleSectionedTableViewAppDelegate.h"

#import "Region.h"

#import "TimeZoneWrapper.h"


//어떤 경우에 사용되는지  모르겠음…???

NSString *localeNameForTimeZoneNameComponents(NSArray *nameComponents);

NSMutableDictionary *regionDictionaryWithNameInArray(NSString *name, NSArray *array);

@implementation RootViewController


@synthesize regions;


#pragma mark -

#pragma mark View lifecycle

- (void)viewDidLoad {

//Foundation Framework 있는 함수로 NSBundle.h 선언되어있음. Localizable.string 있는 파일에서

//key "Time Zones" 되어있는 값을 가져옴 

self.title = NSLocalizedString(@"Time Zones"@"Time Zones title");

}


#pragma mark -

#pragma mark Table view data source methods

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

// Number of sections is the number of regions.

//섹션의 수는 regions 배열의 크기를 돌려줌

return [regions count];

}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

// Number of rows is the number of time zones in the region for the specified section.

// 섹션에 있는 행의 수는 regions 배열에 들어있는 각각의 region 인스턴스로부터

//TimeZoneWrapper 클래스의 배열인 timeZoneWrappers 크기를 돌려줌

Region *region = [regions objectAtIndex:section];

return [region.timeZoneWrappers count];

}


- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {

// The header for the section is the region name -- get this from the region

//at the section index.

// 섹션의 제목은 regions 배열의 section 위치에 있는 region 인스턴스로부터 name 속성을 사용함

Region *region = [regions objectAtIndex:section];

return [region name];

}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

//cell 재활용을 위해 아이디를 부여

static NSString *MyIdentifier = @"MyIdentifier";


//재활용할 cell 없으면 새로 생성

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];

if (cell == nil) {

cell = [[[UITableViewCell allocinitWithStyle:UITableViewCellStyleDefault 

 reuseIdentifier:MyIdentifier] autorelease];

}

// Get the section index, and so the region for that section.

//NSIndexPath 일련의 배열들의 트리 구조를 표현 하는 것으로 부여되는 값들은 

//각각 다음 단계 배열의 인덱스를 의미한다여기서는 index path section - row 이어지면

//각각 지역 정보를 가지고 있는 regions 배열의 인덱스와 time zone 정보를 가지고 있는

//timeZoneWrappers 배열의 인덱스를 의미한다.

//index path에서 regions 인덱스를 가져와 해당 인덱스의 region 인스턴스를 가져온다.

Region *region = [regions objectAtIndex:indexPath.section];

//regions로부터 가져온 region 인스턴스의 timeZoneWrappers 배열에서 index path

//있는 timeZoneWrappers 인덱스를 가져와 해당 위치의 timeZoneWrapper 인스턴스를 가져온다.

TimeZoneWrapper *timeZoneWrapper = [region.timeZoneWrappers objectAtIndex:indexPath.row];


// Set the cell's text to the name of the time zone at the row

//가져온 timeZoneWrapper 선언된 localeName 속성을  셀의 제목으로 설정한다.

cell.textLabel.text = timeZoneWrapper.localeName;

return cell;

}


#pragma mark -

#pragma mark Table view delegate method

/*

 To conform to Human Interface Guildelines, since selecting a row would have no effect (such as navigation), make sure that rows cannot be selected.

 */

//특정 위치의 셀이 선택되었을   처리 내용이 들어갈 메서드

- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath {

return nil;

}


#pragma mark -

#pragma mark Memory management

//메모리 해제

- (void)dealloc {

[regions release];

     [super dealloc];

}


@end


반응형