2016-08-07 2 views

답변

2

하는 것은 다음을 수행 (스위프트 사용)

:

import UIKit 

class tableViewOne: UIViewController{ 

    @IBOutlet var tableView: UITableView! 
    // your data 
    var dummyData = ["data 0","data 1","data 2"] 

    override func viewDidLoad() { 
     super.viewDidLoad() 

    } 

} 

extension tableViewOne: UITableViewDataSource, UITableViewDelegate { 
    // Define no of rows in your tableView 
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
     return dummyData.count 
    } 

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
     // Default cell 
     let cell = tableView.dequeueReusableCellWithIdentifier("Cell")! as UITableViewCell 

     cell.textLabel!.text = dummyData[indexPath.row] 

     return cell; 
    } 

} 

참고 :storyboard에 설치 DataSourceUITableViewDelegate하는 것을 잊지 마십시오. storyboard에 이미 정의 된 경우 프로그래밍 방식으로 정의 할 필요가 없습니다.

+0

감사합니다. 완벽하게 일했습니다! 깨끗한 대답! – Sebbe

+0

감사합니다 @Sebbe :) – MShah

0
  1. table view을 View Controller로 Ctrl + 드래그해야합니다. 당신의보기 컨트롤러 내부의 viewDidLoad()에서

  2. , 당신은 대리인 및 데이터 소스를 설정해야합니다 :

    tableView.dataSource = self 
    tableView.delegate = self 
    
  3. 뷰 컨트롤러 구현해야합니다 :

    class YourViewController : UITableViewDelegate, UITableViewDataSource 
    

이제 View Controller 클래스는 셀/행 수를 반환하는 관련 메서드를 재정의해야합니다.

행운을 비네.

관련 문제