在UITable视图中实现拖放功能

问题描述 投票:0回答:2

**我需要在我的表格视图中实现拖放功能,我在屏幕左侧有一个表格视图,在屏幕右侧有一个图像视图。

我需要从我的表格视图中拖动一个图像到右边的图像视图。

让我解释一下...

我有一个名为"myClass",其中包含属性iD、name和imageURL。

image url包含了photolibrary alasset的url。

我的类.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;

我的类.m

@implementation myClass

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

@end

所以我添加了50个图片细节,iD,name,imageURL为 myClass 对象到一个名为*的NSMutableArray中。BundleImagesArray *

我把它显示在一个表格视图中,我的代码是。

-(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
}

我需要把图片从我的表格视图拖到我的右侧图片视图中,有谁能给我提供一个好的方法。

objective-c xcode ipad uitableview drag-and-drop
2个回答
0
投票

在iPad上,拖放不是一个标准的交互模式。用户不会明白他们应该做什么。你应该允许用户在左侧的表格视图中使用简单的点击来选择一个项目,然后根据选择更新图像视图。请看一下 人机界面指南.

© www.soinside.com 2019 - 2024. All rights reserved.