当当前选定的表格单元格移出屏幕后,如何向其发送消息?
这是我的场景:
我在 UINavigationController
中显示一个 UITableViewController
,并且我自己在子类中绘制单元格。为了使单元格看起来尽可能接近本机单元格,我有一个标志来指示它是否处于过渡状态,以防止当用户从堆栈向上移动时文本颜色明显闪烁表视图的详细信息视图。
目前,我在 -tableView:didSelectRowAtIndexPath:
中设置了转换标志,如下所示:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// (stuff for pushing the detail view on to the navigation stack)
((MyCustomTableViewCell *) [self.tableView cellForRowAtIndexPath: indexPath]).transitioning = YES;
}
这效果相当好,但有一个警告:在列表动画离开屏幕之前,任何人都可以清楚地看到转换为此,当单元格文本从白色(蓝色)变为黑色(蓝色)时。
我的问题:有没有办法从表格视图中获取当前选定的单元格, 它已经转出屏幕了,并向它发送消息吗? (假设它没有被释放,只是被卸载)
或者我只是以错误的方式处理这整件事?
(对于任何考虑说没有人会注意到它的人,请记住,它的现状对我来说是可以接受的,我只是想知道是否有办法让它变得更好。好的 iOS 应用程序都是关于小事情的.)
Here’s my scenario:
I’m showing a UITableViewController
in a UINavigationController
, and I’m drawing the cells myself in a subclass. In order to keep the cells looking as close to possible like native cells, I have a flag that indicates whether it is in a transitional state or not, in order to prevent the text color from visibly flashing when the user moves back up the stack from a detail view to the table view.
Currently, I set my transitioning flag in -tableView:didSelectRowAtIndexPath:
, like so:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// (stuff for pushing the detail view on to the navigation stack)
((MyCustomTableViewCell *) [self.tableView cellForRowAtIndexPath: indexPath]).transitioning = YES;
}
This works rather well, with one caveat: Immediately before the list animates off-screen, the transition is clearly visible to anyone looking for it, as the cell text changes to black (on blue) from white (on blue.)
My question: Is there any way to get the currently selected cell from the table view, after it has transitioned off-screen, and send it a message? (assuming it isn’t being deallocated, simply unloaded)
Or am I simply going about this whole thing the wrong way?
(For anyone considering saying that nobody will notice it, keep in mind that it’s acceptable to me the way that it is, I’m simply wondering if there’s a way for me to make it better. Good iOS applications are all about the little things.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
“防止文本颜色明显闪烁”是什么意思?默认情况下,iOS 表格单元格似乎不会这样做,至少以一种令人不快的方式。也许您可以重新访问 UITableViewCell 实现并确定您是否错误地处理 -setSelected:animated: 和 -setHighlighted:animated
What do you mean by "prevent the text color from visibly flashing"? By default iOS table cells don't appear to do that, at least in an unpleasant way. Perhaps you can revisit your UITableViewCell implementation and determine if you are incorrectly handling -setSelected:animated: and -setHighlighted:animated
UITableView 不保留表中所有单元格的可公开访问的列表。
为了访问所有单元格(包括屏幕外的单元格),您需要维护生成的单元格的单独数组。
现在您已经有了表格中所有单元格的列表,您可以随时向它们发送任何消息。
UITableView does not keep a publicly-accessible list of all the cells in the table.
In order to access all the cells (including ones out of the screen) you need to maintain a separate array of the cells you generate.
Now that you have a list of all the cells in the table, you can send them any message, anytime you want.