Я передаю значения из табличного представления в контроллер представления коллекции, используя контроллер представления SwReveal. когда я нажимаю ячейку в представлении коллекции, я сохраняю индексный путь ячейки коллекции. Но когда я выбираю таблицу и передаю значение в представление коллекции пути индекса. Ячейка не отображает значение. Это нулевой ... вот мой кодКак передать значения из tableview в collectionview
-(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 *)[collectionData cellForItemAtIndexPath: self.displayindex];
[email protected]"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 *)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= [[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 action:@selector(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)buttonPressed:(id)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)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)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;
[email protected]"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];
}
}
Что вы пытались отладить это? Здесь много кода, и его легко диагностировать, просто прочитав его. –
Можете ли вы попытаться объяснить проблему лучше? Какой здесь прецедент? Почему вы пытаетесь получить Cell-объект на определенном indexPath, а не получать, если из dataSource? Вам нужна ячейка или просто данные? Или вы пытаетесь обновить Cell? И ** что ** является «Viewindex»? Выбранный indexPath из 'tableView'? – Sti