UITableView - 保持最底部的单元格滚动到顶部? [英] UITableView - Keep bottom-most cell scrolled to the top?

查看:87
本文介绍了UITableView - 保持最底部的单元格滚动到顶部?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个基于音乐的应用程序。播放列表屏幕是UITableView。它有3个部分:上一曲目,正在播放,下一首曲目。
它们的顺序如下:

Im creating a music based app. The playlist screen is a UITableView. It has 3 sections: Previous Tracks, Now Playing, Next Tracks. They are in order as follows:

-- PREVIOUS TRACKS SECTION --
   Track Z
   Track Y
   Track X
-- NOW PLAYING SECTION --
   Track A
-- NEXT TRACKS --
   Track B
   Track C
   Track D

我总是希望正在播放部分滚动到顶部表视图。
如果出现以下情况,这不是问题:
A)上一曲目部分没有项目或
B)下一曲目部分有足够的曲目传递到UITableView的底部。

I always want the 'Now Playing' section to be scrolled to the top of the table view. This is not a problem if: A) There are no items in the Previous tracks section or B) There are enough tracks in the Next Tracks section to pass beyond the bottom of the UITableView.

但是,如果有前一曲目部分中的10首曲目,正在播放中的一首曲目和下一曲目部分中的2首曲目,那么当我告诉要滚动的表格视图,因此正在播放部分位于视图的顶部,它只是弹回,因此它是视图底部的3个项目(2个下一曲目项目加上当前播放)。

However, if there are, for example 10 tracks in the Previous Tracks section, one in the Currently Playing and 2 in the Next Track section, then when I tell the table view to scroll so the Now Playing section is at the top of the view, it just springs back so it is 3 items from the bottom of the view (the 2 'Next Track' items plus the Currently Playing).

换句话说,看看你的iPod库或iPhone上的任何TableView。我试图实现的是将列表中的最后一首曲目滚动到屏幕顶部并在下面留下空白空格。

To put it another way, look at your iPod library or any TableView on the iPhone. What im trying to acheive is to scroll the last track in the list to the top of the screen and leave blank white space underneath.

有没有办法告诉TableView在这种情况下不要重新回到原位?
我试过在那里玩一个很大的高度单元格,但它的hacky并在TableView中重新排列单元格时会出现问题。

Is there any way of telling the TableView not to spring back into place in this scenario? I have tried playing a large height cell there, but its hacky and causes problems when re-arranging cells in the TableView.

从技术上讲这是Monotouch,但是目标C很好,所以无论什么语言都没问题。

Technically this is Monotouch, but im fine with Objective C, so whatever language is fine.

推荐答案

看看 contentInset 属性。您必须设置底部插入,以便最底部的单元格可见。

Look at the contentInset property which the table view inherits. You will have to set the bottom inset just so that the bottom most cell is visible.

示例:

self.tableView.contentInset = UIEdgeInsetsMake(0, 0, self.tableView.frame.size.height - 88, 0);

这篇关于UITableView - 保持最底部的单元格滚动到顶部?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆