ios - 从多个 UITableView 选定单元格传递图像数组

标签 ios objective-c arrays uitableview

我现在遇到这样的问题。我有一个带有 UITableView 的 UIViewController,我将其设置为当 UITableView 处于编辑模式时它返回 3 - 带有复选标记的圆圈。我的 UITableView 具有带有图像和文本的自定义单元格。当我将 UITableView 置于编辑模式时,我试图将图像数组从多个选定行传递到第二个 View Controller 以在 Collection View 中使用这些图像,但我只是很难传递图像数组.任何建议,将不胜感激。

这是我的 TableView 代码:

-(void)didTapEditBUtton:(id)sender{
if ([self.ribbonTableView isEditing]) {
    viewButton.hidden = YES;
    headerLabel.hidden = NO;
    [ribbonTableView setEditing:NO animated:YES];
    [selectButton setTitle:@"select"];
}
else {
    [selectButton setTitle:@"Cancel"];
    // Turn on edit mode
    headerLabel.hidden = YES;
    viewButton.hidden = NO;
    [ribbonTableView setEditing:YES animated:YES];
    }
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection   (NSInteger)section{
    return [ribbonsArray count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    RibbonCustomCell *cell = (RibbonCustomCell *) [ribbonTableView dequeueReusableCellWithIdentifier:@"RibbonDetail"];

    if (cell != nil)
    {
        RibbonsInfo *ribbonsInfo = [ribbonsArray objectAtIndex:indexPath.row];

    //NSLog(@"%@", ribbonsInfo);

    //Ribbon Image
        cell.ribbonImageView.image = ribbonsInfo.ribbonImage;
        cell.ribbonLabel.text = ribbonsInfo.ribbonName;
    }
    return cell;
}

-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 3;
}

-(void)tableView:(UITableView *)tableView didSelectRowsAtIndexPath:(NSIndexPath *)indexPath{


}

-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath{

}

最佳答案

你应该获取 NSMutableArray 的属性...

@property (nonatomic, strong) NSMutableArray *selectedImages;

- (void)viewDidLoad {
    [super viewDidLoad];
    self.selectedImages = [NSMutableArray new];
}

现在,当您选择或取消选择单元格时,委托(delegate)将被调用 -

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"%@",indexPath);
    RibbonsInfo *ribbonsInfo = [ribbonsArray objectAtIndex:indexPath.row];
    [self.selectedImages addObject:ribbonsInfo.ribbonImage];

}

- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"%@",indexPath);
       if (self.selectedImages.count > 0) {
        [self.selectedImages removeObjectAtIndex:indexPath.row];
       }
}

-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 3;
}

现在 selectedImages 数组包含选定的单元格图像,您可以传递此数组。 希望它能解决您的问题。

关于ios - 从多个 UITableView 选定单元格传递图像数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30905182/

相关文章:

arrays - A* 可接受的数组排序启发式算法

arrays - bash中echo "${array[@]}"echo "${array[*]}"有什么区别

objective-c - 在 iOS 中实现一个简单的折线图

ios - 上传后从存储桶 Amazon Web Service iOS 获取图像 URL

iphone - 改变self的指针

ios - ARC 的 viewController 中的变量

javascript - 连接数组和整数的数组的最佳方法

ios - 如果未显示所有 NavigationLink,则 NavigationView 中 SwiftUI 的 NavigationLink `tag` 和 `selection` 将停止工作

iphone - 如何从 UIImage 获取 NSDATE?

android - iOS 和 Android 的 OpenGL ES 区别