Ios 在UITableView中水平滚动以查看Xcode 6&;中的长单元格;敏捷的
我创建了一个tableviewcontroller并向其中添加了一个表视图。我需要的只是通过向右滑动查看一个长单元格(或行)。我该怎么做?Ios 在UITableView中水平滚动以查看Xcode 6&;中的长单元格;敏捷的,ios,swift,uitableview,Ios,Swift,Uitableview,我创建了一个tableviewcontroller并向其中添加了一个表视图。我需要的只是通过向右滑动查看一个长单元格(或行)。我该怎么做? 只需在tableCell中添加一个简单的UIScrollView,如下所示。这将允许您在单元格内进行水平滚动 override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let
只需在tableCell中添加一个简单的UIScrollView,如下所示。这将允许您在单元格内进行水平滚动
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("reuseIdentifier", forIndexPath: indexPath) as UITableViewCell
// Configure the cell...
/// Horizontal Scroll
var scrollview = UIScrollView(frame: cell.bounds)
scrollview.contentSize = CGSizeMake(cell.bounds.width * 5, cell.bounds.height) // will be 5 times as wide as the cell
scrollview.pagingEnabled = true
cell.contentView.addSubview(scrollview)
return cell
}
欢迎来到StackOverflow。请审阅。我一定会检查它,谢谢…但我不想单独滚动单元格,像excel表格一样向右滚动,所有单元格一起滚动…您可以在滚动视图中包装tableView。。。使tableView尽可能宽,以覆盖所需的所有列。。。然后tableView将上下滚动所有列。。。scrollView将向左和向右滚动所有行。事实上,尝试了此操作但失败,请检查我的其他问题:提交了对其他问题的答案。
import UIKit
class ViewController: UIViewController,UITableViewDelegate,UITableViewDataSource{
var tableviwe:UITableView?
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.tableviwe = UITableView(frame: self.view!.bounds)
self.tableviwe!.delegate = self
self.tableviwe!.dataSource = self;
self.tableviwe?.backgroundColor = UIColor.redColor()
let angle:CGFloat = CGFloat(M_PI_2);//angle角度 double angle;
self.tableviwe?.transform = CGAffineTransformMakeRotation(angle)
self.view?.addSubview(self.tableviwe!)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
//UITableViewDelegate
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let alert = UIAlertView()
alert.title = "Alert"
alert.message = NSString(format: "%@ %d", "My hit ", indexPath.row)
alert.addButtonWithTitle("Ok")
alert.show()
}
//UITableViewDataSource
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1000
}
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat{
return 200.0
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "channel")
cell.textLabel?.text = NSString(format: "%@ %d", "hello my friend", indexPath.row)
let angle:CGFloat = CGFloat(M_PI_2);//angle角度 double angle;
cell.contentView.transform = CGAffineTransformMakeRotation(-angle)
return cell
}
}