ios - 如何将值从 tableview 传递到 collectionview
<p><p>我使用 SwRevealViewController 将值从 TableView 传递到 Collection ViewController 。当我单击 Collection View 中的单元格时,我存储了 Collection View 单元格的索引路径。但是当我选择一个表并将一个值传递给索引路径 Collection View 时。不显示值的单元格。它是空的......这是我的代码</p>
<pre><code>-(void)viewWillAppear:(BOOL)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 *);
cells.subjectLabel.text=@"djhfkjdshfjkhd";
cells.cellView.backgroundColor=;
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 *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)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=[objectAtIndex:0];
//myCell.roomLabel.text = ;
myCell.roomLabel.text= ];
myCell.subjectLabel.text =;
// myCell.cellView.backgroundColor= ;
;
;
;
}
else(indexPath.row == 1) {
NSArray *Object=[objectAtIndex:3];
NSLog(@"objectATIndex 3 %@",Object);
//myCell.roomLabel.text = ;
myCell.roomLabel.text= ];
myCell.subjectLabel.text =;
//myCell.cellView.backgroundColor= ;
;
;
;
// ..... some more code here just like above
}
-(void)buttonPressed:(id)sender
{
NSLog(@"tag number is = %d",);
NSLog(@"Button");
//Storing index path when cancel Button is clicked
deletindexpath = inSection:0];
_appDFel.appindex=deletindexpath;
NSLog(@" _appDFel.appindex %@", _appDFel.appindex);
alert =[initWithTitle:@"Delete session" message:@"Do you want to delete this session" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
alert.delegate=self;
;
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
NSLog(@"indexpath %@",deletindexpath);
if (deletindexpath!=nil) {
//enabling SWReveal view conttroller after cancel button is clicked
Cell *cells = (Cell *);
NSLog(@"cell %@",cells.subjectLabel.text);
NSString *textString=cells.subjectLabel.text;
_appDFel.TextString=textString;
cells.subjectLabel.text=@"NOSession";
cells.cellView.backgroundColor=;
;
NSLog(@"swiping is done here");
;
;
//;
}
</code></pre>
<p>}</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>在我的脑海中,我想说你的单元格不存在,你需要分配/初始化它或 <code>dequeueWithReuseIdentifier</code>。</p>
<p>另外,您正在使用“Cell”来创建您的单元格,而不是 <code>UICollectionViewCell</code> ;除非您使用名为 <code>Cell</code></p> 的自定义单元格,否则这可能是个问题
<p>如果这没有帮助,您能否在描述中添加更多代码? cellforrow 和数据传递方法。</p></p>
<p style="font-size: 20px;">关于ios - 如何将值从 tableview 传递到 collectionview,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/25781219/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/25781219/
</a>
</p>
页:
[1]