展开segue后,UIView在触摸时崩溃

时间:2014-08-29 07:02:40

标签: ios objective-c iphone uiview segue

我有一个UIView在从搜索segue展开后在屏幕触摸时崩溃。它基本上允许用户在第一个UIView中选择一个标签,该标签推送到员工搜索UIView中,用户从列表中选择一个员工。选择后,它将返回到屏幕并为该标签分配所选的员工姓名。所有款式等都应用得很好,所以我正在看一个正确的屏幕,但只要我触摸屏幕做任何其他事情,无论是后退按钮,选择员工标签还是屏幕的其他区域,它只是用Thread 1: EXC_BAD_ACCESS(code=1,address=0xc)崩溃,几乎就像一个错误循环。

Condition.m

#import "ConditionNewVC.h"
#import "EmployeeSearchVC.h"
#import "Condition.h"

@implementation ConditionNewVC

@synthesize condition;

- ( void ) didReceiveMemoryWarning
{
    [ super didReceiveMemoryWarning ];
}

- ( void ) viewDidLoad
{
    [ super viewDidLoad ];

    // Handle the responsible person view touch
    UITapGestureRecognizer *singleFingerTap = [ [ UITapGestureRecognizer alloc ] initWithTarget: self action: @selector( handleResponsiblePersonViewTouch: ) ];
    [ _viewResponsiblePerson addGestureRecognizer: singleFingerTap ];

}

/**
 *  Ready layout prior to view load
 */
- ( void ) viewDidLayoutSubviews
{
    [ super viewDidLayoutSubviews ];
    [ self assignValues ];
}

#pragma mark - Input Controls

/**
 *  Handle the view touch
 *
 *  @param recognizer
 */
- ( void ) handleResponsiblePersonViewTouch: ( UITapGestureRecognizer * ) recognizer
{
    [ self performSegueWithIdentifier: @"searchEmployeeSegue" sender: @"ConditionNewVC" ];
}

#pragma mark - Aesthetics

/**
 *  Assign values to objects
 */
- ( void ) assignValues
{   
    // If as such, assign the passed condition values, otherwise leave as blank
    if ( [ condition.responsiblePersonName length ] > 0 )
    {
        _lblResponsible.text = condition.responsiblePersonName;
    }
    else
    {
        _lblResponsible.text = @"Select responsible person";
    }

}

#pragma mark - Segues

- ( IBAction ) unwindToConditionNewVC: ( UIStoryboardSegue * ) unwindSegue
{
    // Let's get the condition object from the unwound employee search
    EmployeeSearchVC *employeeSearchVC = unwindSegue.sourceViewController;

    // init object in memory if not already allocated
    if ( !condition )
    {
        condition = [ [ Condition alloc ] init ];
    }

    condition = employeeSearchVC.condition;
}

/**
 *  Prepare object data for next view
 *
 *  @param segue    the segue that the view is going to
 *  @param sender   sender of the action
 */
- ( void ) prepareForSegue: ( UIStoryboardSegue * ) segue sender: ( id ) sender
{
    if ( [ [ segue identifier ] isEqualToString: @"searchEmployeeSegue" ] )
    {
        // init object in memory if not already allocated
        if ( !condition )
        {
            condition = [ [ Condition alloc ] init ];
        }

        condition.responsiblePersonName = _lblResponsible.text;

        EmployeeSearchVC *employeeSearchVC = segue.destinationViewController;
        employeeSearchVC.condition = condition;
        employeeSearchVC.unwindSegueToPerform = @"unwindToConditionNewVC";

    }
}

@end

EmployeeSearch.m

    #import "EmployeeSearchVC.h"
#import "Employee.h"
#import "ConditionNewVC.h"

@implementation EmployeeSearchVC

@synthesize unwindSegueToPerform;
@synthesize condition;

- ( void ) didReceiveMemoryWarning
{
    [ super didReceiveMemoryWarning ];
}

- ( void ) viewDidLoad
{
    [ super viewDidLoad ];

    // Instantiate the object manager
    _employeeManager = [ EmployeeManager employeeManager ];
}

- ( void ) viewDidLayoutSubviews
{
    [ super viewDidLayoutSubviews ];
    [ self addStyles ];
}


// stuff to handle employee table view


#pragma mark - Segues

/**
 *  Prepare object data for next view
 *
 *  @param segue    the segue that the view is going to
 *  @param sender   sender of the action
 */
- ( void ) prepareForSegue: ( UIStoryboardSegue * ) segue sender: ( id ) sender
{

    // Get index of row clicked and assign it to a new object to pass into the detail view
    NSIndexPath *indexPathClicked = [ _autocompleteTableView indexPathForSelectedRow ];
    int row = [ indexPathClicked row ];
    Employee *selectedEmployee = [ _matchedEmployees init ][ row ];

    // Search
    if ( [ unwindSegueToPerform isEqualToString: @"unwindToSearchFormVC" ] )
    {
        // Assign the selected employee name to the correct search Param fields
        if ( ![ selectedEmployee isEqual: [ NSNull null ] ] ) {

            // Assign the correct property the selected employee value
            if ( [ strProperty isEqualToString: @"responsiblePerson"] )
            {
                searchParams.responsiblePerson = nil;
                searchParams.responsiblePerson = selectedEmployee.fullName;
            }
            else if ( [ strProperty isEqualToString: @"author"] )
            {
                searchParams.author = nil;
                searchParams.author = selectedEmployee.fullName;
            }

        }

        // Assign the value to the next detail view
        SearchFormVC *searchFormVC = segue.destinationViewController;
        searchFormVC.searchParams = searchParams;
    }

    // Condition search
    if ( [ unwindSegueToPerform isEqualToString: @"unwindToConditionNewVC" ] )
    {
        // Assign the selected employee name to the correct condition fields
        if ( ![ selectedEmployee isEqual: [ NSNull null ] ] ) {
            condition.responsiblePersonName = nil;
            condition.responsiblePersonName = selectedEmployee.fullName;
        }

        // Assign the value to the next detail view
        ConditionNewVC *conditionNewVC = segue.destinationViewController;
        conditionNewVC.condition = condition;
    }



}

@end

0 个答案:

没有答案