开发者

UITableView selectRowAtIndexPath does nothing

I am having a problem getting selectRowAtIndexPath to work. If I call the selectRowForIndexPath function before starting an animation, that flips the tableview in question, the tableview will not highlight the tableview row as requested. In fact, it seems that doing anything to the tableview does not give any response. What can be the problem?

I also called setNeedsDisplay and whatnot, but the functions don't seem to be doing anything.

- (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;
     开发者_JAVA技巧   }


    } 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];
}


Get rid of

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

I have a feeling this doesn't complete before you tell the table to select that row and hence the specified index path might not exist.

Simply replace that call with [m_oTableView reloadData] and see if that works

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜