在UITableview中实现拖放

时间:2011-09-26 14:09:59

标签: objective-c xcode ipad uitableview drag-and-drop

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

我需要将图像从表格视图拖到右侧图像视图。

让我解释..

我有一个名为“ myClass ”的类,其中包含属性iD,name和imageURL。

图片网址保存了光学图书馆的网址。

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

所以我用iD,name,imageURL作为 myClass 对象添加了50个图像细节到一个名为* BundleImagesArray *

的NSMutableArray中

我在表格视图中显示了它。我的代码是:

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

我需要将图像从表格视图拖到右侧图像视图。任何人都可以为我提供一个好方法

1 个答案:

答案 0 :(得分:0)

拖放不是iPad上的标准交互模式。用户不会理解他们应该做什么。您应该允许用户使用简单的点击选择左侧表格视图中的项目,然后根据选择更新图像视图。看看Human Interface Guidelines