开发者

implement Drag and Drop in UITable view

开发者 https://www.devze.com 2023-04-07 22:33 出处:网络
**I need to implement Drag and Drop in my table view.I have a table View in left side of my screen and i have an image View on right side of an screen.

**I need to implement Drag and Drop in my table view.I have a table View in left side of my screen and i have an image View on right side of an screen.

I need to Drag a image from my table view to right side image view.

let me explain ..

I have an class named as "myClass" which contains the properties iD, name and imageURL.

image url holds the photolibrary alasset url.

myClass.h

@interface myClass: NSObject {
    NSInteger iD;
    NSString *name;
    NSString *imageURL;
}

@property (nonatomic, assign) NSInteger iD;
@property (nonatomic, assign) NSString *name;
@property (nonatomic, assign) NSString *imageURL;

myClass.m

@implementation myClass

@synthesize iD;
@synthesize name;
@synthesize imageURL;

@end

So I added 50 image details with iD, name, imageURL as myClass objects in to an NSMutableArray named as *BundleImagesArray *

i displayed it in a table view. my code is:

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger) section {
    //getting all image details with iD,name,imageURL as **myClass** objects     
    BundleImagesArray = [staticDynamicHandler getImageFromBundle];

    int count =  [BundleImagesArray count];

    for (int i = 0; i<count; i++) {
        //this array for easy scrolling after first time the table is loaded.
        [imageCollectionArrays addObject:[NSNull null]];

    }
    return count;

}

cellForRowAtIndexPath

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{    

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }

    //removing all the subviews
  开发者_开发技巧  if ([cell.contentView subviews]) {
        for (UIView *subview in [cell.contentView subviews]) {
            [subview removeFromSuperview];
        }
    }

    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    [cell setAccessoryType:UITableViewCellAccessoryNone];

    myClass *temp = [BundleImagesArray objectAtIndex:indexPath.row];


    //adding image view 
    UIImageView *importMediaSaveImage=[[[UIImageView alloc] init] autorelease];
    importMediaSaveImage.frame=CGRectMake(0, 0, 200,135 );
    [cell.contentView addSubview:importMediaSaveImage]; 

    //adding image label
    UILabel *sceneLabel=[[[UILabel alloc] initWithFrame:CGRectMake(220,0,200,135)] autorelease]; 
    sceneLabel.font = [UIFont boldSystemFontOfSize:16.0];
    sceneLabel.textColor=[UIColor blackColor];
    [cell.contentView addSubview:sceneLabel];

    sceneLabel.text = temp.name;

    if([imageCollectionArrays objectAtIndex:indexPath.row] == [NSNull null]){ 

        //getting photlibrary image thumbnail as NSDAta
        NSData *myData = [self photolibImageThumbNailData::temp.imageURL]

        importMediaSaveImage.image =[UIImage imageWithData:myData ];

        [imageCollectionArrays replaceObjectAtIndex:indexPath.row withObject:importMediaSaveImage.image];
    } else {
        importMediaSaveImage.image = [imageCollectionArrays objectAtIndex:indexPath.row];
    }

    temp = nil;
    return cell
}

I need to Drag a image from my table view to my right side image view.can any one provide me a good way to do it


Drag and drop is not a standard interaction mode on the iPad. Users will not understand what they are supposed to do. You should allow a user to select an item in the left-hand table view using a simple tap instead and then update the image view based on the selection. Take a look at the Human Interface Guidelines.

0

精彩评论

暂无评论...
验证码 换一张
取 消