数据不在两个对象之间交换

时间:2012-09-18 02:16:16

标签: objective-c ios5

所以我有这个包含一些值的类。在我的viewcontroller中,我创建了一堆这些对象,当我点击它们时,我可以为它们设置数据。然后,当我移动它们并且对象相交时,我有一个方法应该在它们之间交换数据。现在,当我逐步完成它时,一切似乎都能正常工作。 Self甚至可以保存来自其他对象的数据,但是当我再次单击该对象时,它会返回到其旧数据。有没有人有任何想法为什么会这样?

我通过弹出窗口将数据设置为每个对象,需要单击以将数据设置为该对象,因此如果我能清楚地看到它,我不知道从哪里获取此数据当我单步执行时会改变它

以下是交换数据的方法:

这在我的touchesEnded方法上发生。

Seat.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];

    } 
}

0 个答案:

没有答案