2013 이전/iOS개발

[iOS 개발] UITableView 기본 delegate, datasource

하구루 2017. 2. 25. 16:19

UITableView 를 사용하다 보면 항상 기본적인 delegate와 datasource의 소스들을 다른 소스에서 긁어서 쓰고 있다.

이참에 항상 쓰는 소스만 정리해서 올려 놓으려고 한다.
#pragma mark -
#pragma mark tableview delegate

// 섹션의 갯수
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    // Return the number of sections.
    
    return 1;
}

// 각 섹션당 로우의 갯수
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    // Return the number of rows in the section.
    
    return 5;
    
}

// 각 셀 그리기
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *CellIdentifier = @"CalendarCell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        
            
    }
    
    
    return cell;
}


// 셀이 선택 되었을때 수행할 내용 
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
     
}


// 각셀의 높이 
-(CGFloat) tableView : (UITableView *) tableView heightForRowAtIndexPath : (NSIndexPath *)indexPath{
    
    return 45;    
}


반응형