2011-09-26 69 views
0

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

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

让我解释一下..

我命名为 “myClass的”,其中包含的属性ID,名称和IMAGEURL一类。

图片网址包含光谱库alasset网址。

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

我需要从我的表视图view.can任何一个拖动图像到我的右侧图像提供给我一个很好的办法做到这一点

回答

0

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