• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

ios - 如何将值从 tableview 传递到 collectionview

[复制链接]
菜鸟教程小白 发表于 2022-12-13 09:01:21 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我使用 SwReveal View Controller 将值从 TableView 传递到 Collection View Controller 。当我单击 Collection View 中的单元格时,我存储了 Collection View 单元格的索引路径。但是当我选择一个表并将一个值传递给索引路径 Collection View 时。不显示值的单元格。它是空的......这是我的代码

-(void)viewWillAppearBOOL)animated{
    text=seltext;
    NSLog(@"text %@",text);

 // HERE I AM GETTING VALUES FROM TABLE VIEW CONTROLLER

    self.displayindex=Viewindex;
    NSLog(@"self dispaly %@",Viewindex);

  // HERE I AM GETTING INDEX PATH OF SELECTED COLLECTION CELL

    Cell *cells = (Cell *)[collectionData cellForItemAtIndexPath: self.displayindex];
    cells.subjectLabel.text=@"djhfkjdshfjkhd";
    cells.cellView.backgroundColor=[UIColor greenColor];
    NSLog(@"cell is %@",cells);
    NSLog(@"text %@",text);

// CELL IS NULL HERE AND NOTHING IS DISPLAYING EVEN IF I PASS THE CELL FRO ITEM INDEXPATH

        }




- (UICollectionViewCell *)collectionViewUICollectionView *)collectionView cellForItemAtIndexPathNSIndexPath *)indexPath
{
    // we're going to use a custom UICollectionViewCell, which will hold subject and room number
    Cell *myCell = [collectionData dequeueReusableCellWithReuseIdentifier"TableCell"



                                                             forIndexPath:indexPath];
    if ((indexPath.row == 20) ||  (indexPath.row == 21)  || ( indexPath.row == 23)  ||  ( indexPath.row == 24))
    {
        myCell.hidden=YES;
    }




   // if (indexPath.row < 20 || indexPath.row == 22  )
 if (indexPath.row < 10 || (indexPath.row >14 && indexPath.row <20) ||indexPath.row ==22)
{


    if (indexPath.row == 0) {
       NSArray *Object=  [[jsonData valueForKey"TimeTabledPeriods"]objectAtIndex:0];


        //myCell.roomLabel.text = [NSString stringWithFormat"{%ld,%ld}", (long)indexPath.section ,  (long)indexPath.row];
        myCell.roomLabel.text= [NSString stringWithFormat"Room: %@", [Object valueForKey"RoomDescription"]];

        myCell.subjectLabel.text =  [Object valueForKey"SubjectDescription"];

       // myCell.cellView.backgroundColor= [UIColor grayColor];
        [myCell.redXbuttonOutlet setTag:indexPath.row];
        [myCell.LearningChoiceYellowOutlet setHidden:YES];


        [myCell.redXbuttonOutlet addTarget:self actionselector(buttonPressed forControlEvents:UIControlEventTouchUpInside];

    }
   else  (indexPath.row == 1) {

        NSArray *Object=  [[jsonData valueForKey"TimeTabledPeriods"]objectAtIndex:3];
       NSLog(@"objectATIndex 3 %@",Object);


       //myCell.roomLabel.text = [NSString stringWithFormat"{%ld,%ld}", (long)indexPath.section ,  (long)indexPath.row];
        myCell.roomLabel.text= [NSString stringWithFormat"Room: %@", [Object valueForKey:@"RoomDescription"]];

        myCell.subjectLabel.text =  [Object valueForKey:@"SubjectDescription"];
        //myCell.cellView.backgroundColor= [UIColor grayColor];
        [myCell.redXbuttonOutlet setTag:indexPath.row];
       [myCell.LearningChoiceYellowOutlet setHidden:YES];
        [myCell.redXbuttonOutlet addTarget:self action:@selector(buttonPressed forControlEvents:UIControlEventTouchUpInside];
      // ..... some more code here just like above
    }


-(void)buttonPressedid)sender
{

        NSLog(@"tag number is = %d",[sender tag]);
        NSLog(@"Button");


//Storing index path when cancel Button is clicked
        deletindexpath = [NSIndexPath indexPathForRow:[sender tag] inSection:0];
    _appDFel.appindex=deletindexpath;

        NSLog(@" _appDFel.appindex %@", _appDFel.appindex);


        alert =[[UIAlertView alloc]initWithTitle:@"Delete session" message:@"Do you want to delete this session" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
        alert.delegate=self;
        [alert show];

    }




- (void)alertViewUIAlertView *)alertView clickedButtonAtIndexNSInteger)buttonIndex{
    NSLog(@"indexpath %@",deletindexpath);
    if (deletindexpath!=nil) {

//enabling SWReveal view conttroller after cancel button is clicked        

        Cell *cells = (Cell *)[collectionData cellForItemAtIndexPath:deletindexpath];

        NSLog(@"cell %@",cells.subjectLabel.text);
        NSString *textString=cells.subjectLabel.text;
        _appDFel.TextString=textString;
        cells.subjectLabel.text=@"NOSession";
        cells.cellView.backgroundColor=[UIColor redColor];
        [cells.redXbuttonOutlet removeFromSuperview];
        NSLog(@"swiping is done here");
        [self fetchinfOfData];
        [self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];
        //[self performSegueWithIdentifier:@"SwipeLeftSegue" sender:nil];

           }

}



Best Answer-推荐答案


在我的脑海中,我想说你的单元格不存在,你需要分配/初始化它或 dequeueWithReuseIdentifier

另外,您正在使用“Cell”来创建您的单元格,而不是 UICollectionViewCell ;除非您使用名为 Cell

的自定义单元格,否则这可能是个问题

如果这没有帮助,您能否在描述中添加更多代码? cellforrow 和数据传递方法。

关于ios - 如何将值从 tableview 传递到 collectionview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25781219/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap