프로그램/iOS

iOS 테이블뷰 사용법

잡식성초보 2016. 2. 22. 11:25

테이블뷰를 만드는 방법이다...

일단 테이블뷰에 들어갈 셀을 만들어서 identifier를 지정해준다 난중에 저값으로 불러오니 알아서 작성.



그후 테이블뷰를 사용할 컨트롤로에 테이블뷰를 만든후 datasource와 delegate 그리고 outlet을 잡아준다.




//셀 높이를 준다

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

{

    return 셀높이;

    

}



//셀 갯수를 준바

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

{

    return 셀갯수;

}


//셀을 작성한다

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

{

    

    NSString *const identifier = @"생성해놓은 테이블뷰셀";

    생성해놓은 테이블뷰셀 *cell = [tableView dequeueReusableCellWithIdentifier:identifier];

    

    if(cell == nil){

        

        [tableView registerNib:[UINib nibWithNibName:identifier bundle:nil]

                                                        forCellReuseIdentifier:@"셀에 등록한 identifier명"];

        

    cell = [tableView dequeueReusableCellWithIdentifier:@"셀에 등록한 identifier명


"];

    NSDictionary *rowDic = [self.CellArray objectAtIndex:indexPath.row];

        

    return cell;

}

반응형