我使用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];
}
}
你有什麼試圖對此進行調試?這裏有很多代碼,通過閱讀它並不容易診斷。 – 2014-09-15 14:55:23
你可以嘗試更好地解釋這個問題嗎?這裏的用例是什麼?你爲什麼試圖在特定的indexPath中獲取Cell對象,而不是從dataSource中獲取?你需要這個單元格,還是僅僅是數據?還是你想更新一個單元? ** ** Viewindex是什麼?從'tableView'中選擇的indexPath? – Sti 2014-09-20 17:30:11