2016-08-15 2 views
1

루프 내에서 다중 테이블 뷰를 만들 수 있습니까? 나는 그 일을하려했지만 실패했다. 그렇게 할 수 있습니까? 내보기 컨트롤러에서 여러 tableview 만들 수 있습니다.다중 테이블 뷰 내부에서 루프 생성 (신속)

for var i in 0...1{ 
     var tableView = UITableView() 
    tableView = UITableView(frame: CGRectMake(0,0,500,100)) 

    tableView.separatorColor = UIColor.clearColor() 

    tableView.dataSource = self 
    tableView.delegate = self 

    self.view.addSubview(tableView) 

    showsArray = ["House of Cards","Arrested Development","Orange is the New Black","Unbreakable","Daredevil","The Killing","BoJack Horseman","Mad Men","Breaking Bad","Bates Motel"] 
} 

func numberOfSectionsInTableView(tableView: UITableView) -> Int 
{ 
    return 1 
} 

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int 
{ 
    return showsArray.count 
} 

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell 
{ 
    let cellFrame = CGRectMake(0, 0, self.tableView.frame.width, 52.0) 
    var retCell = UITableViewCell(frame: cellFrame) 

    var textLabel = UILabel(frame: CGRectMake(10.0, 0.0, UIScreen.mainScreen().bounds.width - 20.0, 52.0 - 4.0)) 
    textLabel.textColor = UIColor.blackColor() 
    textLabel.text = showsArray[indexPath.row] 
    retCell.addSubview(textLabel) 

    return retCell 
} 

func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat 
{ 
    return 52.0 
} 

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) 
{ 
    tableView.deselectRowAtIndexPath(indexPath, animated: true) 
} 

func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat 
{ 
    if section == 0 
    { return 64.0 
    } 

    return 32.0 
} 

func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? 
{ 
    let ret = UILabel(frame: CGRectMake(10, 0, self.tableView.frame.width - 20, 32.0)) 
    ret.backgroundColor = UIColor.clearColor() 
    ret.text = "TV Shows" 
    ret.textAlignment = NSTextAlignment.Center 
    return ret 
} 

func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? 
{  let more = UITableViewRowAction(style: .Normal, title: "More") { action, index in 
     print("more button tapped") 
    } 
    more.backgroundColor = UIColor(patternImage: UIImage(named: "Unknown.jpg")!) 

    let favorite = UITableViewRowAction(style: .Normal, title: "Favorite") { action, index in 
     print("favorite button tapped") 
    } 
    favorite.backgroundColor = UIColor.orangeColor() 

    let share = UITableViewRowAction(style: .Normal, title: "Share") { action, index in 
     print("share button tapped") 
    } 
    share.backgroundColor = UIColor.blueColor() 

    return [share, favorite, more] 
} 

func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool { 
    // the cells you would like the actions to appear needs to be editable 
    return true 
} 

func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) { 
    // you need to implement this method too or you can't swipe to display the actions 
} 
} 

override func didReceiveMemoryWarning() { 
    super.didReceiveMemoryWarning() 
    // Dispose of any resources that can be recreated. 
} 


} 

정의가 이전 값과 충돌합니다.

+0

나는 XY 문제를 냄새가 난다. – Sweeper

+0

나는 당신의 경우에 대해 생각한다. 당신은 테이블보다는 여러 섹션을 사용해야한다. – xmhafiz

답변