View从didSelectRowAtIndexPath主细节VC ios中多次推送

时间:2014-04-10 05:56:43

标签: ios objective-c uiviewcontroller uinavigationcontroller

我遇到一个问题,即在选择一行时多次推送相同的视图,如果用户一直点击同一行就会崩溃。

MasterDetailVC.m

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    LAClaimReport *record = [_claimReports objectAtIndex:indexPath.row];
    if ([record.submitted isEqualToNumber:@1])
    { // if i click on clicking here VC is getting pushed and pushed. 
        [self.detailViewController showReadonlyViewForClaimReport:record];
    }
    else
    {
        [self.detailViewController showEditViewForClaimReport:record];
    }
}

LADetailViewController.m

   @interface LADetailViewController()
    {
        LAClaimReport *_claimRecord;
    }
-(void) showEditViewForClaimReport:(LAClaimReport *) claimReport
{
    _claimRecord = claimReport;

    [self performSegueWithIdentifier:@"toEditView" sender:self];
// calls LAClaimReportViewController
}

-(void) showReadonlyViewForClaimReport:(LAClaimReport *) claimReport
{

    _claimRecord = claimReport;


    [self performSegueWithIdentifier:@"toReadonlyView" sender:self];
// calls LACreateReportViewController.

}

-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"toEditView"])
    {
        LAClaimReportViewController *viewController = segue.destinationViewController;
        viewController.claimReport = _claimRecord;
    }
    else if ([[segue identifier] isEqualToString:@"toReadonlyView"])
    {
        LACreateReportViewController *viewController = segue.destinationViewController;
        viewController.claimReport = _claimRecord;
    }
}

LAClaimReportViewController& LACreateReportViewController是两个差异。 VC具有来自LADetailViewController的segue。我希望在多次点击masterDetailVC的同一行时不要多次推送VC(LACreateReportViewControllerLAClaimReportViewController)。请帮助。

1 个答案:

答案 0 :(得分:0)

您可以检查View是否已被推送。如果是,那么不要再推它。如果它没有推,那就推吧。

为此你可以使一个实例变量可能是一个bool。让我们称之为isPushed。按下视图时生成isPushed = true;。弹出它然后制作isPushed = false;

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    LAClaimReport *record = [_claimReports objectAtIndex:indexPath.row];
    if ([record.submitted isEqualToNumber:@1] && !isPushed)
    { // if i click on clicking here VC is getting pushed and pushed. 
        isPushed = true;
        [self.detailViewController showReadonlyViewForClaimReport:record];
    }
    else
    {
        [self.detailViewController showEditViewForClaimReport:record];
    }
}

以上只是一种方式。有一点是这样的:[record.submitted isEqualToNumber:@1]总是假的?如果是,那么你想检查我的想法。

希望这会有帮助。