ios 에서 사용자 정의 cell,사용자 정의 UITableView Cell
5714 단어 iosuitableviewcell
1.빈 항목 만 들 기,이름:
2.UITableView Controller 를 만 들 고 xib 를 동시에 만 듭 니 다.
3.AppDelegate.m 에서 window 의 루트 컨트롤 러 를 방금 만 든 TableViewController 로 설정 합 니 다.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
TableViewController *tableViewController = [[[TableViewController alloc] init] autorelease]; //
//
self.window.rootViewController = tableViewController;
[self.window makeKeyAndVisible];
return YES;
}
4.사용자 정의 UITableView Cell 만 들 기:5.사용자 정의 cell 의 xib 드래그 앤 드 롭 에 필요 한 컨트롤 을 만 듭 니 다.
사용자 인터페이스 선택
빈 xib 를 만 듭 니 다.
Cell 컨트롤 을 끌 어 옵 니 다.
사용자 정의 cell 컨트롤 을 완성 합 니 다.
cell 컨트롤 을 설정 한 Identfier.
Cell 류 를 연결 하고 컨트롤 의 출력 구 를 TableView Cell.h 파일 에 연결 합 니 다.
6.TableView Controller 류 인 코딩 에 대해 의뢰 방법 에 사용자 정의 Cell 을 설정 합 니 다.
#import "TableViewController.h"
#import "TableViewCell.h"
@interface TableViewController (){
NSMutableArray *tableData; //
}
@end
@implementation TableViewController
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
//
tableData = [[NSMutableArray alloc] init];
for (int i = 0; i< 10; i++) {
[tableData addObject:[NSString stringWithFormat:@"MyCellDemon%i",i]];
}
// row cell
self.tableView.rowHeight = 90;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
#warning Potentially incomplete method implementation.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
#warning Incomplete method implementation.
return [tableData count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// cellIdentifier cell
static NSString *CellIdentifier = @"TableViewCell";
// cell
TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
// xib cell
cell = [[[NSBundle mainBundle] loadNibNamed:@"TableViewCell" owner:self options:nil] lastObject];
}
//
cell.titleLabel.text = [tableData objectAtIndex:indexPath.row];
cell.content.text = @" ";
//
cell.iamge.image = [UIImage imageNamed:@"testImage.jpg"];
return cell;
}
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
}
@end
최종 효과:이상 이 바로 본 고의 모든 내용 입 니 다.여러분 의 학습 에 도움 이 되 고 저 희 를 많이 응원 해 주 셨 으 면 좋 겠 습 니 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Swift의 패스트 패스Objective-C를 대체하기 위해 만들어졌지만 Xcode는 Objective-C 런타임 라이브러리를 사용하기 때문에 Swift와 함께 C, C++ 및 Objective-C를 컴파일할 수 있습니다. Xcode는 S...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.