ios 에서 사용자 정의 cell,사용자 정의 UITableView Cell

5714 단어 iosuitableviewcell
정의 cell 에서 UITableView Cell 계승 하기
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 
최종 효과:

이상 이 바로 본 고의 모든 내용 입 니 다.여러분 의 학습 에 도움 이 되 고 저 희 를 많이 응원 해 주 셨 으 면 좋 겠 습 니 다.

좋은 웹페이지 즐겨찾기