在目前我有以下的代碼如下所示:UICollectionViewCell定製Segue公司的ViewController連接錯誤
GroupsViewController.m
#import "GroupsViewController.h"
#import "GroupsHomeViewController.h"
#import "CustomCell.h"
@interface GroupsViewController()
{
NSArray *arrayOfImages;
NSArray *arrayOfDescriptions;
NSString * _titleForNextVC;
}
@end
@implementation GroupsViewController
{
NSString *reuseIdentifier;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[[self GroupsCollectionView]setDataSource:self];
[[self GroupsCollectionView]setDelegate:self];
reuseIdentifier= @"SmallIcon";
arrayOfImages = [[NSArray alloc]initWithObjects:@"A.png",@"B.png",@"C.png",nil];
arrayOfDescriptions = [[NSArray alloc]initWithObjects:@"A",@"B",@"C",nil];
}
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return [arrayOfDescriptions count];
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
CustomCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
[[cell IconImage]setImage:[UIImage imageNamed:[arrayOfImages objectAtIndex:indexPath.item]]];
[[cell IconLabel]setText:[arrayOfDescriptions objectAtIndex:indexPath.item]];
return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
CustomCell *cell = (CustomCell *) [self collectionView:collectionView cellForItemAtIndexPath:indexPath];
_titleForNextVC = cell.IconLabel.text;
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"GroupsHomeSegue"]) {
GroupsHomeViewController *vc = (GroupsHomeViewController *)segue.destinationViewController;
vc.titleText = _titleForNextVC;
}
}
- (void)setTitleText:(NSString *)titleText {
_titleText = _titleForNextVC;
// Set Title of your ViewController
self.title = _titleText;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
//Dispose of any resources that can be recreated.
}
// Toggle View Button
- (IBAction)cellToggleAction:(id)sender {
if([reuseIdentifier isEqualToString:@"SmallIcon"]){
[email protected]"ListView";
[sender setImage:[UIImage imageNamed:@"LargeIcon"]];
}
else if
([reuseIdentifier isEqualToString:@"ListView"]){
[email protected]"LargeIcon";
[sender setImage:[UIImage imageNamed:@"SmallIcon"]];
}
else if
([reuseIdentifier isEqualToString:@"LargeIcon"]){
[email protected]"SmallIcon";
[sender setImage:[UIImage imageNamed:@"ListView"]];
}
[self.GroupsCollectionView reloadData];
}
//Toggled Cell Sizes
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
CGSize cellSize;
if([reuseIdentifier isEqualToString:@"SmallIcon"])
cellSize = CGSizeMake(100, 130);
else if
([reuseIdentifier isEqualToString:@"ListView"])
cellSize = CGSizeMake(320, 50);
else if
([reuseIdentifier isEqualToString:@"LargeIcon"])
cellSize = CGSizeMake(320, 360);
return cellSize;
}
@end
GroupsHomeViewController.m
#import "GroupsHomeViewController.h"
@interface GroupsHomeViewController()
@end
@implementation GroupsHomeViewController
-(void)viewDidLoad{
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
好這個問題似乎是我無法通過我的自定義搜索獲得新的ViewController
,一旦我點擊了我的UiCollectionViewcells
之一。基本上,我點擊我的UICollectionView
中的一個單元格,標題消失,但它什麼也沒有做。它應該打開GroupsHomeViewController
並將View Controller的標題設置爲放置在剛剛單擊的單元格中的標籤。我甚至無法看到我的當前標題是否會起作用,因爲我無法顯示我的GroupsHomeViewController
。
我假設我錯過了一行代碼,但我很努力地找出它可能是因爲沒有收到任何錯誤消息。
此外,我只想指出,我是新來的,只是在過去一個月左右的空閒時間開發我的應用程序。所以,如果你能幫助我解決這個問題,我將不勝感激,並且我事先感謝你對我可能錯過的任何方向。
您會得到更好的如果你的問題是*最小*,完整和可驗證的答案(http://stackoverflow.com/help/mcve)。也就是說,給我們最少量的代碼來重現你的問題,而不是給我們完整的課程。 – EmilioPelaez
你是如何添加賽格? – CaptJak
我控制從StoryView模式下ViewController頂部的GroupsViewController Orange/Yellow按鈕中點擊,然後將它放到我的第二個空ViewController上,例如GroupsHomeViewController。 –