我创建了一个tableviewcontroller并为其添加了一个表视图。我需要的只是通过向右滑动来查看长单元格(或行)。我怎样才能做到这一点?
答案 0 :(得分:1)
只需在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
}
答案 1 :(得分:0)
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
}
}