我有一个带有文本字段和textview的表视图.我已经实现了这个代码,就像这个苹果示例代码https://developer.apple.com/library/ios/documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/KeyboardManagement/KeyboardManagement.html所建议的那样.
@IBOutlet var myTableView: UITableView
func keyboardWasShown (notification: NSNotification)
{
println("keyboard was shown")
var info = notification.userInfo
var keyboardSize = info.objectForKey(UIKeyboardFrameBeginUserInfoKey).CGRectValue().size
myTableView.contentInset = UIEdgeInsetsMake(0, 0, keyboardSize.height, 0)
myTableView.scrollIndicatorInsets = myTableView.contentInset
}
func keyboardWillBeHidden (notification: NSNotification)
{
println("keyboard will be hidden")
myTableView.contentInset = UIEdgeInsetsZero
myTableView.scrollIndicatorInsets = UIEdgeInsetsZero
}
override func viewDidLoad() {
super.viewDidLoad()
NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWasShown:", name: UIKeyboardDidShowNotification, object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillBeHidden:", name: UIKeyboardWillHideNotification, object: nil)
}
Run Code Online (Sandbox Code Playgroud)
当我点击滚动视图的"文本"时,就在屏幕顶部上方,但是当我松开键盘时,它仍然向上滚动.这就像第一次使用后无法修改insets属性一样.我的错是什么?
我在自定义单元格中有一个UIButton,我想在用户按下该按钮时触发一个动作但是我需要知道按下UIButton的哪一行.
这是我的代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
[self configureCell:cell atIndexPath:indexPath];
return cell;
...
[button addTarget:self action:@selector(buttonPressedAction:)forControlEvents:UIControlEventTouchUpInside];
}
- (void)buttonPressedAction:(UIButton *)button
{
//int row = indexPath.row;
//NSLog(@"ROW: %i",row);
}
Run Code Online (Sandbox Code Playgroud)
如何将indexPath作为参数传递给我的选择器?
ios ×2
cocoa-touch ×1
ipad ×1
iphone ×1
keyboard ×1
objective-c ×1
swift ×1
uiscrollview ×1
uitableview ×1