2015-07-15 4 views
0

Когда пользователь пытается прокручивать таблицу (идет по высоте клавиатуры), она автоматически прокручивается назад в верхнюю часть таблицы, оставляя пользователя не нажатым ни одной из клавиш в нижних строках Таблица. Как отключить автопрокрутку? Обратите внимание, что это отличается от свойства scrollsToTop.UITableView сохраняет autoscrolling to top

import UIKit 

class KeyboardViewController: UIInputViewController, UITableViewDelegate, UITableViewDataSource { 

var tableView: UITableView = UITableView() 
let screenSize: CGRect = UIScreen.mainScreen().bounds 


let buttonTitles = [ 
    "XX", 
    "YY" 
] 

override func viewDidLoad() { 
    super.viewDidLoad() 

    let screenWidth = screenSize.width 
    let screenHeight = screenSize.height 
    tableView.frame = CGRectMake(0,0,screenWidth,screenHeight - 40) 
    tableView.delegate = self 
    tableView.dataSource = self 

    tableView.registerClass(UITableViewCell.self,forCellReuseIdentifier: "cell") 

    self.view.addSubview(tableView) 


} 

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

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
    var cell:UITableViewCell = tableView.dequeueReusableCellWithIdentifier("cell") as! UITableViewCell 
    cell.textLabel?.text = self.buttonTitles[indexPath.row] 
    cell.textLabel?.textAlignment = .Center 
    cell.textLabel?.font = UIFont(name: "Helvetica Neue", size: 14) 
    cell.textLabel?.textColor = UIColor.whiteColor() 
    cell.textLabel?.numberOfLines = 0 
    cell.backgroundColor = UIColor(red: 176/255, green: 15/255, blue: 15/255, alpha: 1.0) 
    cell.preservesSuperviewLayoutMargins = false 
    cell.layoutMargins = UIEdgeInsetsZero 
    cell.separatorInset = UIEdgeInsetsZero 
    return cell 

} 

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { 
    var string = buttonTitles[indexPath.row] 
    (textDocumentProxy as! UIKeyInput).insertText("\(string)") 
} 
+1

Показать больше кода. Не должно быть неправильного внешнего видаDidLoad. – kostek

+0

Вы устанавливаете контентOffset или contentInsets в любом месте этого viewController? – villy393

+0

@kostek - спасибо - просто предоставлено все в файле .swift – vk2015

ответ

0

Переместить код, за исключением

tableView.delegate = self 
tableView.dataSource = self 

в viewWillAppear

+0

Предполагая, что я сделал это правильно (см. Ниже) - это не сработало: 'override func viewDidLoad() { super.viewDidLoad() tableView.delegate = self tableView.dataSource = само } переопределение FUNC viewWillAppear (анимированные: Bool) { super.viewWillAppear (анимированный) пусть screenWidth = screenSize.width пусть ScreenHeight = screenSize.height tableView.frame = CGRectMake (0, 0, screenWidth, screenHeight - 40) tableView.registerClass (UITableViewCell.self, forCellReuseIdentifier: "cell") self.view.addSubview (tableView) } ' – vk2015

+0

Вы добавили какие-либо ограничения в свой вид таблицы? –

+0

Извините - я новичок в этом, но предположил, что tableView.frame = CGRectMake (0,0, screenWidth, screenHeight - 40) было достаточной информацией для размещения представления без каких-либо дополнительных ограничений – vk2015