IPHONE APPLICATION Develop-4
1. TableSample이라는 프로젝트 파일을 생성합니다.
// // TableListController.m // TableSample // // Created by mac3 on 11. 1. 12.. // Copyright 2011 __MyCompanyName__. All rights reserved. //
#import "TableListController.h"
@implementation TableListController
#pragma mark - #pragma mark 테이블.....
#pragma mark - #pragma mark Initialization
/* - (id)initWithStyle:(UITableViewStyle)style { // Override initWithStyle: if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad. self = [super initWithStyle:style]; if (self) { // Custom initialization. } return self; } */
#pragma mark - #pragma mark View lifecycle
/* - (void)viewDidLoad { [super viewDidLoad];
// Uncomment the following line to display an Edit button in the navigation bar for this view controller. // self.navigationItem.rightBarButtonItem = self.editButtonItem; } */
/* - (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]; } */ /* // Override to allow orientations other than the default portrait orientation. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations. return (interfaceOrientation == UIInterfaceOrientationPortrait); } */
#pragma mark - #pragma mark Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { // Return the number of sections. return 5; //섹션의 개수를 리턴. 이것이 없으면 에러 발생 } /* - (NSString *) tableView:(UITableView *) tableView titleForHeaderInSection:(NS integer)section { return @"Header Title"; } */ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { // Return the number of rows in the section. NSInteger rowNum;
if(section=0){ rowNum-10; } else if (section==1) {
rowNum=3; } else{ rowNum=5; } return rowNum; //테이블의 개수를 리턴. 이것이 없으면 에러 발생 }
// Customize the appearance of table view cells. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"Section No.:%d, Row No.: %d", [indexPath section], [indexPath row]);
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];//UITableViewCellStyleDefault를 TableViewCellStyleSubtitle로 바꾸어주면 subtitle을 함께 보여줌, default는 서브타이틀이 나오지 않음.UITableViewCellStyleValue1과 UITableViewCellStyleValue2가 있음 }
// Configure the cell... UIImage *img = [UIImage imageNamed:@"image.jpg"]; cell.imageView.image =img; cell.textLabel.text=@"List Title"; cell.detailTextLabel.text=@"Sub Title"; cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator; // UITableViewCellAccessoryDisclosureButton은 상세내용을 보기위해 사용 return cell; }
/* // Override to support conditional editing of the table view. - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { // Return NO if you do not want the specified item to be editable. return YES; } */
/* // Override to support editing the table view. - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) { // Delete the row from the data source. [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; } else if (editingStyle == UITableViewCellEditingStyleInsert) { // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view. } } */
/* // Override to support rearranging the table view. - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath { } */
/* // Override to support conditional rearranging of the table view. - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath { // Return NO if you do not want the item to be re-orderable. return YES; } */
#pragma mark - #pragma mark Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { // Navigation logic may go here. Create and push another view controller. /* <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil]; // ... // Pass the selected object to the new view controller. [self.navigationController pushViewController:detailViewController animated:YES]; [detailViewController release]; */ }
#pragma mark - #pragma mark Memory management
- (void)didReceiveMemoryWarning { // Releases the view if it doesn't have a superview. [super didReceiveMemoryWarning];
// Relinquish ownership any cached data, images, etc. that aren't in use. }
- (void)viewDidUnload { // Relinquish ownership of anything that can be recreated in viewDidLoad or on demand. // For example: self.myOutlet = nil; }
- (void)dealloc { [super dealloc]; }
@end
|