UITableView selectRowAtIndexPath什么都不做

时间:2011-01-18 03:15:17

标签: iphone uitableview iphone-sdk-3.0

我在使selectRowAtIndexPath工作时遇到问题。如果我在开始动画之前调用selectRowForIndexPath函数,则会翻转有问题的tableview,tableview将不会按要求突出显示tableview行。事实上,似乎对tableview做任何事情都没有给出任何回应。可能是什么问题?

我还调用了setNeedsDisplay等等,但这些函数似乎没有做任何事情。

- (void)setCurrentTAType:(MHAbstractTAParameter *)aoTAParameter sequenceNo:(NSInteger)aiSequence {

    m_iSequence = aiSequence;
    NSInteger iSelectedRow = 0;

    if ([aoTAParameter isKindOfClass:[MHOverlayTAParameter class]]) {
        m_iDisplayType = MHChartTADisplayOverlay;
        [m_oTableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];

        MHOverlayTAParameter *oOverlayParam = (MHOverlayTAParameter *)aoTAParameter;

        switch (oOverlayParam.iOverlayTAType) {
            case MHChartOverlayNone:
                iSelectedRow = 0;
                break;
            case MHChartOverlaySMA:
                iSelectedRow = 1;
                break;
            case MHChartOverlayWMA:
                iSelectedRow = 2;
                break;
            case MHChartOverlayEMA:
                iSelectedRow = 3;
                break;
            case MHChartOverlaySAR:
                iSelectedRow = 4;
                break;
            case MHChartOverlayBoll:
                iSelectedRow = 5;
                break;
            default:
                iSelectedRow = 0;
                break;
        }


    } else {

        m_iDisplayType = MHChartTADisplayUnderlay;
        [m_oTableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];

        MHUnderlayTAParameter *oUnderlayParam = (MHUnderlayTAParameter *)aoTAParameter;

        switch (oUnderlayParam.iUnderlayTAType) {
            case MHChartUnderlayNone:
                iSelectedRow = 0;
                break;
            case MHChartUnderlayVolume:
                iSelectedRow = 1;
                break;
            case MHChartUnderlayRSI:
                iSelectedRow = 2;
                break;
            case MHChartUnderlayMACD:
                iSelectedRow = 3;
                break;
            case MHChartUnderlayMTM:
                iSelectedRow = 4;
                break;
            case MHChartUnderlayROC:
                iSelectedRow = 5;
                break;
            case MHChartUnderlayFastSTC:
                iSelectedRow = 6;
                break;
            case MHChartUnderlaySlowSTC:
                iSelectedRow = 7;
                break;
            case MHChartUnderlayWilliamPctR:
                iSelectedRow = 8;
                break;
            case MHChartUnderlayOBV:
                iSelectedRow = 9;
                break;
            case MHChartUnderlayPVT:
                iSelectedRow = 10;
                break;
            case MHChartUnderlayDMI:
                iSelectedRow = 11;
                break;
            case MHChartUnderlayVolumeP:
                iSelectedRow = 12;
                break;
            case MHChartUnderlayTurnover:
                iSelectedRow = 13;
                break;
            case MHChartUnderlayTurnoverP:
                iSelectedRow = 14;
                break;
            case MHChartUnderlayVolatility:
                iSelectedRow = 15;
            default:
                iSelectedRow = 0;
                break;
        }
    }

    NSIndexPath *oIndexPath = [NSIndexPath indexPathForRow:iSelectedRow inSection:0];

    [m_oTableView selectRowAtIndexPath:oIndexPath animated:YES scrollPosition:UITableViewScrollPositionMiddle];
    [m_oTableView setNeedsDisplay];
}

1 个答案:

答案 0 :(得分:2)

摆脱

[m_oTableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];

我觉得在你告诉表选择那一行之前这没有完成,因此指定的索引路径可能不存在。

只需将该通话替换为[m_oTableView reloadData],看看是否有效