아이폰 개발 시작 4 – Interface Builder 없이 UItable View 프로그램 만들기
I am assuming that you know the implementation of UITableview with interface builder ,if not please have a look at the iPhone Programming Tutorial - Hello World with UITableView.
Now Please Observe the steps carefully
step-1 : Create window based application.
Xcode—>File—>Create New Project. Give the project name as ” TV” .
Step-2 :Observe the default files generated by the xcode . Those files are.
Classes
TVAppDelegate.h
TVAppDelegate.m
Other Sources
Table_Views_1_Prefix.pch
main.m
Resources
MainWindow.xib
info.plist
Frameworks
UIKit.framework
Foundation.framework
CoreGraphics.framework
Products
TV.app
So , these are our default files list.
Think here we are not going to use the interface builder ,so need not to touch mainwindow.xib file.
So we have only two files to change. i.e TVAppDelegate.h and TVAppDelegate.m
So we need TableView right?
TVAppDelegate.h file default code is
//
// TVAppDelegate.h
// TV
//
// Created by iappdevs on 29/12/08.
// Copyright Lorvent 2008. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface TVAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@end
modified code is
//
// TVAppDelegate.h
// TV
// Created by iappdevs on 13/12/08.
// Copyright iappdevs 2008. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface TVAppDelegate : NSObject
{
UIWindow *window;
UITableView *myTable;
NSArray *theSimpsons;
}
@end
TableView means it contains data source and delegate right?
So we are providing the data to table with our code so we need to extend them as
@interface TVAppDelegate : NSObject
Ok till now we declared the table view in appdelagate.m , now we have to implement the code about the table view in the appdelegate.m
We are using
@protocol UITableViewDataSource
@required
- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section;
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
Default TVAppDelegate.m code is
//TVAppDelegate.m
// TV
// Created by srinivas gourishetty on 13/12/08.
// Copyright iappdevs 2008. All rights reserved.
//
#import “TVAppDelegate.h”
@implementation TVAppDelegate
@synthesizewindow;
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
// Override point for customization after application launch
[window makeKeyAndVisible];
}
- (void)dealloc
{
[window release];
[super dealloc];
}
@end
Modified code is
// TVAppDelegate.m
// Tasks
//
// Created by Admin on 30/08/08.
// Copyright 2008 __MyCompanyName__. All rights reserved.
//
/*
This is the first program in the Table View series.
It demonstrates a minimalist table.
*/
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "TVAppDelegate.h"
@implementation TVAppDelegate
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] ;
myTable = [[UITableView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame style:UITableViewStylePlain];
theSimpsons = [[NSArray arrayWithObjects:
@"Homer Jay Simpson",
@"Marjorie "Marge" Simpson",
@"Bartholomew "Bart" J. Simpson",
@"Lisa Marie Simpson",
@"Margaret "Maggie" Simpson",
@"Abraham J. Simpson",
@"Santa's Little Helper",
@"Ned Flanders",
@"Apu Nahasapeemapetilon",
@"Clancy Wiggum",
@"Charles Montgomery Burns",nil] retain];
myTable.dataSource = self;
[window addSubview:myTable];
[window makeKeyAndVisible];
}
- (void)dealloc {
[window release];
[myTable release];
[theSimpsons release];
[super dealloc];
}
// DataSource methods
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [theSimpsons count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"simpsons"];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"simpsons"] autorelease];
}
// Set up the cell
cell.text = [theSimpsons objectAtIndex:indexPath.row];
return cell;
}
@end
Your out put isPlease let me know if any thing was wrong. and i am not a good writer try to understand and steps was very easy and source code
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.