在 UITable 视图中实现拖放

发布于 2024-12-06 23:40:57 字数 3285 浏览 1 评论 0原文

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

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

让我解释一下..

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

图像 url 保存照片库资产 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

因此,我将 50 个带有 iD、名称、imageURL 的图像详细信息作为 myClass 对象添加到名为 *< 的 NSMutableArray 中em>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
}

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

**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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

电影里的梦 2024-12-13 23:40:57

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文