如何让UITextView进入时向上滚动?

发布于 2024-09-08 03:14:21 字数 499 浏览 0 评论 0原文

我有一个 UITextView 包含在 UITableViewCell 中。最初显示视图时,布局是正确的,但是一旦我单击 UITextView,它就不会自动向上滚动,并且整个 UITextView 变得不可见。

此图像是 UITextView 未激活时的图像:

http://img13.imageshack.us/ img13/3894/unloaded.png

这是当我单击 UITextView 使其处于活动状态时:

img337.imageshack.us/img337/2583/loaded.png (在链接之前添加“http://” ,我不能发布多个超链接)

我希望带有 UITextView 的单元格向上滚动。我怎样才能实现这个目标?

任何建议表示赞赏。

胡里奥·塞萨尔

I have a UITextView included in a UITableViewCell. The layout is correct when the views are initially displayed, but once I click in the UITextView it DOES NOT automatically scrolls up and the whole UITextView becomes invisible.

This image is when the UITextView is not active:

http://img13.imageshack.us/img13/3894/unloaded.png

And this one is when I clicked in the UITextView to make it active:

img337.imageshack.us/img337/2583/loaded.png (Put "http://" before the link, I can't post more than one Hyperlink)

I want the cell with the UITextView to scroll up. How can I achieve this?

Any suggestions are appreciated.

Julio Cezar

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

苄①跕圉湢 2024-09-15 03:14:21

最简单的方法是为要向上移动的项目创建一个 IBOutlet,然后在选择文本字段时在代码中执行类似以下操作:

myTextView.center.y = 200 或其他您认为合适的 y 值。

The simplest way would be to make an IBOutlet for the items you want to move up, and then in the code do something like this when your text field is selected:

myTextView.center.y = 200 or whatever y value you see fit.

放低过去 2024-09-15 03:14:21

我已经做到了。我的解决方案不是最好的,但它工作得很好:一切都发生在 tableView:cellForRowAtIndexPath:

1) 对于每个具有 UITextView 的单元格,我有一个 NSDictionary:我使用特定的键将所有 UITextView 保存在 NSDictionary 上的单元格上。

2)我还有另一个 NSDictionary ,其中包含在 tableView:cellForRowAtIndexPath 中创建的 indexPath 对象。如果单元格 A 有 UITextView A,它们在 NSDictionaries 中将具有相同的键。

3)我实现 UITextViewDelegate 并调用 textViewDidBeginEditing:这是我的代码:

  • (void)textFieldDidBeginEditing: (UITextField *)textField {

NSArray *keys = [self.answersDic allKeysForObject:textField];

id *key = (id *)[keys objectAtIndex:0];

NSIndexPath *tempIndex=[self.indexPathForViews objectForKey:key];

[tableViewLocal scrollToRowAtIndexPath:tempIndex atScrollPosition:UITableViewScrollPositionTop 动画:YES];

观察

a)answersDic 是保存我的UITextView 的NSDictionary。

b)indexPathForViews 是保存我的 IndexPaths 的 NSDictionary。

c) 这段代码最重要的部分:使视图向上滚动的方法:

[tableViewLocalscrollToRowAtIndexPath:tempIndex atScrollPosition:UITableViewScrollPositionTopanimated:YES];

所以,就是这样。感谢您的帮助!

I've already done it. My solution is not the best but it works very well: everything happens on tableView:cellForRowAtIndexPath:

1) For every cell that has a UITextView I have a NSDictionary: I save all my UITextView's on the cells on NSDictionary with a particular key.

2) And I also have another NSDictionary with the indexPath objects that are created in tableView:cellForRowAtIndexPath. If a cell A has UITextView A, they will have the same key in the NSDictionaries.

3) I implement the UITextViewDelegate and call textViewDidBeginEditing: here is my code:

  • (void)textFieldDidBeginEditing: (UITextField *)textField {

NSArray *keys = [self.answersDic allKeysForObject:textField];

id *key = (id *)[keys objectAtIndex:0];

NSIndexPath *tempIndex=[self.indexPathForViews objectForKey:key];

[tableViewLocal scrollToRowAtIndexPath:tempIndex atScrollPosition:UITableViewScrollPositionTop animated:YES];

}

OBSERVATIONS:

a) answersDic is the NSDictionary where my UITextViews are saved.

b) indexPathForViews is the NSDictionary where my IndexPaths are saved.

c) the most important part of this code: the method, that brings the view to scroll up:

[tableViewLocal scrollToRowAtIndexPath:tempIndex atScrollPosition:UITableViewScrollPositionTop animated:YES];

So, thats it. Thanks for your help!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文