0

所以我有这个类包含一些值。在我的视图控制器中,我创建了一堆这些对象,当我单击它们时,我可以为它们设置数据。然后,当我移动它们并且对象相交时,我有一个方法可以在它们之间交换数据。现在,当我逐步完成时,一切似乎都正常。Self 甚至保存来自另一个对象的数据,但是当我再次单击该对象时,它会返回到其旧数据。有谁知道为什么会发生这种情况?

我通过一个弹出窗口将数据设置为每个对象,需要单击确定以将数据设置为该对象,所以我不明白如果我能清楚地看到它确实改变了它会从哪里获取这些数据当我走过

这是交换数据的方法:

这发生在我的 touchesEnded 方法上。

座位.h

#import <UIKit/UIKit.h>
#import "CustomUIScrollView.h"
#import "PopOverViewController.h"

@interface Seat : UIView

@property (nonatomic) CGRect rectangle;
@property (strong, nonatomic) CustomUIScrollView *sv;

@property (assign) int seatId;
@property (assign) int seatsSelfObjectIndex;

@property (strong,nonatomic) NSString *firstName;

@property (assign,nonatomic) CGColorRef selectedfillColor;

@property (nonatomic) int swapDataWithSeatInt;
@property (strong, nonatomic) Seat *swapDataWtihSeat;

@property (assign) CGPoint tempLoc;

@property (assign) BOOL didSeatIntersect;


@end




- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [touches anyObject];
    CGPoint location = [touch locationInView:[self superview]];
    self.center = location;
    for (int i = 0; i < seats.count; i++)
         {
             if (CGRectIntersectsRect(self.frame, [[seats objectAtIndex:i]frame]))
             {
                 if (i != seatsSelfObjectIndex)
                 {
                     swapDataWithSeatInt = i;
                     swapDataWtihSeat = [seats objectAtIndex:swapDataWithSeatInt];
                     didSeatIntersect = YES;
                 }
             }

         }
}

- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{

    selectedfillColor = [UIColor clearColor].CGColor;
    [self setNeedsDisplay];

    if (!didSeatIntersect)
    {
        [self setCenter:tempLoc];

    }
    else 
    {

        NSString *tempFirstName = [[seats objectAtIndex:swapDataWithSeatInt]firstName];

        [[seats objectAtIndex:swapDataWithSeatInt ] setFirstName:self.firstName];

       [self setFirstName:tempFirstName];

    } 
}
4

0 回答 0