2014-08-28 4 views
0

테이블보기에 128 개의 셀을 표시하려고합니다. 그러나 어떤 이유로 테이블보기는 최대 5 개의 셀을 표시합니다. 코드에서 반환 한 행 수를 확인한 결과 5보다 큽니다. 따라서 해당 부분이 맞을 것이라고 확신합니다. 또한, 사용자 지정 셀에 대한 코드를 작성했습니다. 이것이이 행동에 기여합니까? 그렇다면 어떻게해야합니까? 그렇지 않다면 내가 뭘 잘못하고 있니? */테이블보기는 제한된 수의 셀을 표시합니까?

import Foundation 
import UIKit 
import CoreLocation 



    class TableViewController: UITableViewController{ 

     var rowNumber: String! 

     override func viewDidLoad() { 
      super.viewDidLoad() 
      //println("Count is : \(dataArray.count)") 
      // Do any additional setup after loading the view, typically from a nib. 
     } 

     override func didReceiveMemoryWarning() { 
      super.didReceiveMemoryWarning() 
      // Dispose of any resources that can be recreated. 
     } 
     override func numberOfSectionsInTableView(tableView: UITableView!) -> Int { 
      return 1; 
     } 

     override func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int { 
      //println("Here Count is : \(dataArray.count)") 
      return dataArray.count 
     } 

     override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! { 

      let cellId = "cell" 
      var cell = tableView.dequeueReusableCellWithIdentifier(cellId) as? myCustomCell 
      //UITableViewCell 

      if nil==cell { 
       cell = myCustomCell(reuseIdentifier: cellId) 

      } 

      if let ip = indexPath{ 
       var dict: NSDictionary! = dataArray.objectAtIndex(indexPath.row) as NSDictionary 
       cell!.myTitle.text = dict.objectForKey("name") as String 

      } 
      return cell 

     } 

     override func tableView(tableView: UITableView!, didSelectRowAtIndexPath: NSIndexPath){ 
      //println("Clicked \(didSelectRowAtIndexPath.row)") 
     } 

     override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) { 

      if(segue.identifier == "centerDetails"){ 
       var svc = segue!.destinationViewController as CellClickController 
       var selectIndex = self.tableView.indexPathForCell(sender as UITableViewCell) 
       svc.cellIdx = selectIndex.row 
      } 
     } 

    } 

감사 테이블 뷰

/* Custom cell code */ 

class myCustomCell: UITableViewCell{ 
    @IBOutlet var myTitle: UILabel! 
    @IBOutlet var mySubtitle: UILabel! 

    convenience required init(reuseIdentifier: String!){ 
     self.init(style: UITableViewCellStyle.Value1, reuseIdentifier: reuseIdentifier) 
    } 

} 

은/* 코드!

+1

'tableView (numberOfRowsInSection)'의'println' 결과는 무엇입니까? –

답변

0

UITableView 방법 dequeueReusableCellWithIdentifier은 한 번에 5-ish 셀만 인스턴스화되는 이유입니다. UITableView은 화면을 채우는 데 충분한 UITableViewCell 개체 만 생성합니다. 스크롤 오프하여 더 이상 볼 수 없게되면 재사용 대기열에 들어갑니다. 빠르게 스크롤하는 경우 화면이 필요로하는 것보다 더 많은 셀을 만들 수 있지만 일반적으로 화면을 덮을 정도로만 사용합니다.

표시 할 각 색인 경로에 대해 UITableViewCell을 새로 작성할 수 있습니다. 그러나 개체 참조 자체를 유지하지 않으면 화면 밖으로 스크롤 할 때 범위가 벗어납니다.. 클래스를 관리하는 배열에 추가하여이 작업을 수행 할 수 있습니다.