当当前选定的表格单元格移出屏幕后,如何向其发送消息?

发布于 2024-10-18 04:08:15 字数 852 浏览 3 评论 0原文

这是我的场景:

我在 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 技术交流群。

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

发布评论

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

评论(2

晚风撩人 2024-10-25 04:08:15

“防止文本颜色明显闪烁”是什么意思?默认情况下,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

酒绊 2024-10-25 04:08:15

UITableView 不保留表中所有单元格的可公开访问的列表。
为了访问所有单元格(包括屏幕外的单元格),您需要维护生成的单元格的单独数组。



@interface MyViewController : UIViewController 
{
   NSMutableArray* tableCells;
}



@implementation MyViewController

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableCells == nil)
      tableCells = [[NSMutableArray alloc] init];

    UITableViewCell* cell;
    if (indexPath.row < [tableCells count])
    {
        // Return a cell from the cached list
        cell = (UITableViewCell*)[tableCells objectAtIndex:indexPath.row];
    }
    else
    {
        // Create a new cell
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault  reuseIdentifier:@"identifier"];  

        // Customize and fill the cell with content anyway you wish
        // ...
    }

    return cell;
}

现在您已经有了表格中所有单元格的列表,您可以随时向它们发送任何消息。

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.



@interface MyViewController : UIViewController 
{
   NSMutableArray* tableCells;
}



@implementation MyViewController

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableCells == nil)
      tableCells = [[NSMutableArray alloc] init];

    UITableViewCell* cell;
    if (indexPath.row < [tableCells count])
    {
        // Return a cell from the cached list
        cell = (UITableViewCell*)[tableCells objectAtIndex:indexPath.row];
    }
    else
    {
        // Create a new cell
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault  reuseIdentifier:@"identifier"];  

        // Customize and fill the cell with content anyway you wish
        // ...
    }

    return cell;
}

Now that you have a list of all the cells in the table, you can send them any message, anytime you want.

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