how to touch and drag objects in a nsaaray

I am trying to touch and move objects inside a nsarray as so. I can't figure out what to do next. Here is the code to show what I'm trying to do (Obviously doesn't work, but gives an idea). Perhaps someone can guide me.

     cardKeys = [[NSArray alloc] initWithObjects:
            @"a",
            @"b",
            @"c",
            @"d",
                                 nil];

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

{
    UITouch *myTouch = [touches anyObject];
  startPoint = [myTouch locationInView:self.view];

    [cardKeys:startPoint.x:startPoint.y];


}   


}

Answers


Your code is poorly formatted. Ex. extraneous pair of curly braces in the method, incorrect indentation. You should consider reading a good book on Objective-C and iOS development, like Programming iOS 5.

Onto your question. I have no idea how you display the NSStrings in that array, why it's global and not a property/ivar, etc. but one way to make something draggable is to make it a UIView subclass, implement touchesBegan and touchesMoved (as you have), grab the point the user touched in your coordinate system, compare it to the point the person's finger is when it moves, then offset your position based on that.


Need Your Help

How to create object required for the class constructor in inversion of control?

c++ unit-testing tdd inversion-of-control

I am programming in c++ using TDD, which suggests to use inversion of control when creating objects (when creating objects of certain class, pass constructed objects to it's constructor). This is f...

Getting the current date (and time) in Django

python django django-queryset django-orm

I was wondering what is the best way to get the current date in a django application.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.