我正在使用Xcode 6制作应用程序。我有两个表视图
控制器,Root和Second,现在我想从Second传递数据
表视图控制器到集合视图控制器。我加了一个
segue但有一个例外。不知道我哪里出问题了。
SecondViewController.h
#import <UIKit/UIKit.h>
@interface SecondTableViewController : UITableViewController
@property(nonatomic, strong) NSString *businessName;
@end
code for CollectionViewController.m
#import "CollectionViewController.h"
#import "CollectionViewCell.h"
@interface CollectionViewController ()
@end
@implementation CollectionViewController
NSArray * favBC;
NSArray * relToMe;
NSArray * repByMe;
NSArray * redForApp;
NSArray * appBC;
static NSString * const reuseIdentifier = @"collectionCell";
- (void)viewDidLoad {
[super viewDidLoad];
// Uncomment the following line to preserve selection between presentations
// self.clearsSelectionOnViewWillAppear = NO;
favBC = [NSArray arrayWithObjects:@"IDEA1",@"NEW",@"IN VAL...",@"IN ESTI...",@"READY...",@"APPROV...",@"IT
CHAN ...“,@” UNDER ...“,@” IMPLEM“,@” CLOSED“,无];
relToMe = [NSArray arrayWithObjects:@"IDEA2",@"NEW",@"IN VAL...",@"IN ESTI...",@"READY...",@"APPROV...",@"IT
CHAN ...“,@” UNDER ...“,@” IMPLEM“,@” CLOSED“,无];
repByMe = [NSArray arrayWithObjects:@"IDEA3",@"NEW",@"IN VAL...",@"IN ESTI...",@"READY...",@"APPROV...",@"IT
CHAN ...“,@” UNDER ...“,@” IMPLEM“,@” CLOSED“,无];
redForApp = [NSArray arrayWithObjects:@"IDEA4",@"NEW",@"IN VAL...",@"IN ESTI...",@"READY...",@"APPROV...",@"IT
CHAN ...“,@” UNDER ...“,@” IMPLEM“,@” CLOSED“,无];
appBC = [NSArray arrayWithObjects:@"IDEA5",@"NEW",@"IN VAL...",@"IN ESTI...",@"READY...",@"APPROV...",@"IT
CHAN ...“,@” UNDER ...“,@” IMPLEM“,@” CLOSED“,无];
// Register cell classes
[self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:reuseIdentifier];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
#pragma mark <UICollectionViewDataSource>
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
if([_businessName2 isEqualToString:@"IDEA1"]){
return [favBC count];
}else if ([_businessName2 isEqualToString:@"IDEA2"]){
return [relToMe count];
}else if ([_businessName2 isEqualToString:@"IDEA3"]){
return [repByMe count];
}else if ([_businessName2 isEqualToString:@"IDEA4"]){
return [redForApp count];
}else if ([_businessName2 isEqualToString:@"IDEA5"]){
return [appBC count];
}
return 0;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier
forIndexPath:indexPath];
if([_businessName2 isEqualToString:@"IDEA1"]){
cell.bcRequestLabel.text = [favBC objectAtIndex:indexPath.row];
}else if ([_businessName2 isEqualToString:@"IDEA2"]){
cell.bcRequestLabel.text = [favBC objectAtIndex:indexPath.row];
}else if ([_businessName2 isEqualToString:@"IDEA3"]){
cell.bcRequestLabel.text = [favBC objectAtIndex:indexPath.row];
}else if ([_businessName2 isEqualToString:@"IDEA4"]){
cell.bcRequestLabel.text = [favBC objectAtIndex:indexPath.row];
}else if ([_businessName2 isEqualToString:@"IDEA5"]){
cell.bcRequestLabel.text = [favBC objectAtIndex:indexPath.row];
}
// Configure the cell
return cell;
}
#pragma mark <UICollectionViewDelegate>
/*
// Uncomment this method to specify if the specified item should be highlighted during tracking
- (BOOL)collectionView:(UICollectionView *)collectionView shouldHighlightItemAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
*/
/*
// Uncomment this method to specify if the specified item should be selected
- (BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
*/
/*
// Uncomment these methods to specify if an action menu should be displayed for the specified item, and react to actions performed on
该项目
- (BOOL)collectionView:(UICollectionView *)collectionView shouldShowMenuForItemAtIndexPath:(NSIndexPath *)indexPath {
return NO;
}
- (BOOL)collectionView:(UICollectionView *)collectionView canPerformAction:(SEL)action forItemAtIndexPath:(NSIndexPath
*)indexPath withSender:{id)sender {
return NO;
}
- (void)collectionView:(UICollectionView *)collectionView performAction:(SEL)action forItemAtIndexPath:(NSIndexPath *)indexPath
withSender:{id)sender {
}
*/
@end
#import "SecondTableViewController.h"
#import "CollectionViewController.h"
@interface SecondTableViewController ()
@end
@implementation SecondTableViewController
NSArray * favBC;
NSArray * relToMe;
NSArray * repByMe;
NSArray * redForApp;
NSArray * appBC;
- (void)viewDidLoad {
[super viewDidLoad];
favBC = [NSArray arrayWithObjects:@"IDEA1",@"NEW",@"IN VAL...",@"IN ESTI...",@"READY...",@"APPROV...",@"IT
CHAN ...“,@” UNDER ...“,@” IMPLEM“,@” CLOSED“,无];
relToMe = [NSArray arrayWithObjects:@"IDEA2",@"NEW",@"IN VAL...",@"IN ESTI...",@"READY...",@"APPROV...",@"IT
CHAN ...“,@” UNDER ...“,@” IMPLEM“,@” CLOSED“,无];
repByMe = [NSArray arrayWithObjects:@"IDEA3",@"NEW",@"IN VAL...",@"IN ESTI...",@"READY...",@"APPROV...",@"IT
CHAN ...“,@” UNDER ...“,@” IMPLEM“,@” CLOSED“,无];
redForApp = [NSArray arrayWithObjects:@"IDEA4",@"NEW",@"IN VAL...",@"IN ESTI...",@"READY...",@"APPROV...",@"IT
CHAN ...“,@” UNDER ...“,@” IMPLEM“,@” CLOSED“,无];
appBC = [NSArray arrayWithObjects:@"IDEA5",@"NEW",@"IN VAL...",@"IN ESTI...",@"READY...",@"APPROV...",@"IT
CHAN ...“,@” UNDER ...“,@” IMPLEM“,@” CLOSED“,无];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if([_businessName isEqualToString:@"Favorite BC"]){
return [favBC count];
}else if ([_businessName isEqualToString:@"Related to me"]){
return [relToMe count];
}else if ([_businessName isEqualToString:@"Reported by me"]){
return [repByMe count];
}else if ([_businessName isEqualToString:@"Ready for approval"]){
return [redForApp count];
}else if ([_businessName isEqualToString:@"Approved BC"]){
return [appBC count];
}
return 0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"Business2Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier
forIndexPath:indexPath];
if(cell == nil){
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
复用标识符:simpleTableIdentifier];
}
if([_businessName isEqualToString:@"Favorite BC"]){
cell.textLabel.text = [favBC objectAtIndex:indexPath.row];
}else if ([_businessName isEqualToString:@"Related to me"]){
cell.textLabel.text = [relToMe objectAtIndex:indexPath.row];
}else if ([_businessName isEqualToString:@"Reported by me"]){
cell.textLabel.text = [repByMe objectAtIndex:indexPath.row];
}else if ([_businessName isEqualToString:@"Ready for approval"]){
cell.textLabel.text = [redForApp objectAtIndex:indexPath.row];
}else if ([_businessName isEqualToString:@"Approved BC"]){
cell.textLabel.text = [appBC objectAtIndex:indexPath.row];
}
// Configure the cell...
return cell;
}
/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
// Return NO if you do not want the specified item to be editable.
return YES;
}
*/
/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
} else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
*/
/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath
toIndexPath:(NSIndexPath *)toIndexPath {
}
*/
/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
// Return NO if you do not want the item to be re-orderable.
return YES;
}
*/
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
if([segue.identifier isEqualToString:@"collectDetail"])
{
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
CollectionViewController *destViewController = segue.destinationViewController;
if([_businessName isEqualToString:@"Favorite BC"]){
destViewController.businessName2 = [favBC objectAtIndex:indexPath.row];
}else if ([_businessName isEqualToString:@"Related to me"]){
destViewController.businessName2 = [relToMe objectAtIndex:indexPath.row];
}else if ([_businessName isEqualToString:@"Reported by me"]){
destViewController.businessName2 = [repByMe objectAtIndex:indexPath.row];
}else if ([_businessName isEqualToString:@"Ready for approval"]){
destViewController.businessName2 = [redForApp objectAtIndex:indexPath.row];
}else if ([_businessName isEqualToString:@"Approved BC"]){
destViewController.businessName2 = [appBC objectAtIndex:indexPath.row];
}
destViewController.title = destViewController.businessName2;
}
}
@end
code for CollectionViewController.h
#import <UIKit/UIKit.h>
@interface CollectionViewController : UICollectionViewController
@property(nonatomic, strong) NSString *businessName2;
@end
code for CollectionViewCell.h
#import <UIKit/UIKit.h>
@interface CollectionViewCell : UICollectionViewCell
@property (weak, nonatomic) IBOutlet UILabel *bcRequestLabel;
@end
code for CollectionViewCell.m
#import "CollectionViewCell.h"
@implementation CollectionViewCell
@end
<b>and the error:<b>
2015-08-13 15:45:37.500 WACProject2[4049:82472] -[UICollectionViewCell bcRequestLabel]: unrecognized selector sent to instance 0x7fb031f59ab0
2015-08-13 15:45:37.503 WACProject2[4049:82472] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason:
'-[UICollectionViewCell bcRequestLabel]:无法识别的选择器已发送
到实例0x7fb031f59ab0'
*** First throw call stack:
(
0 CoreFoundation 0x0000000110722f35 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x00000001103bbbb7 objc_exception_throw + 45
2 CoreFoundation 0x000000011072a04d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x000000011068227c ___forwarding___ + 988
4 CoreFoundation 0x0000000110681e18 _CF_forwarding_prep_0 + 120
5 WACProject2 0x000000010fe8be7b -[CollectionViewController collectionView:cellForItemAtIndexPath:] + 187
6 UIKit 0x000000011113d41b -[UICollectionView _createPreparedCellForItemAtIndexPath:withLayoutAttributes:applyAttributes:]
+ 244
7 UIKit 0x000000011113eb54 -[UICollectionView _updateVisibleCellsNow:] + 3445
8 UIKit 0x0000000111142801 -[UICollectionView layoutSubviews] + 243
9 UIKit 0x0000000110b88973 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 521
10 QuartzCore 0x00000001143fdde8 -[CALayer layoutSublayers] + 150
11 QuartzCore 0x00000001143f2a0e _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
12 QuartzCore 0x00000001143f287e _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
13 QuartzCore 0x000000011436063e _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 242
14 QuartzCore 0x000000011436174a _ZN2CA11Transaction6commitEv + 390
15 QuartzCore 0x0000000114361db5 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 89
16 CoreFoundation 0x0000000110657dc7 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
17 CoreFoundation 0x0000000110657d20 __CFRunLoopDoObservers + 368
18 CoreFoundation 0x000000011064db53 __CFRunLoopRun + 1123
19 CoreFoundation 0x000000011064d486 CFRunLoopRunSpecific + 470
20 GraphicsServices 0x0000000113cf19f0 GSEventRunModal + 161
21 UIKit 0x0000000110b0f420 UIApplicationMain + 1282
22 WACProject2 0x000000010fe8c3e3 main + 115
23 libdyld.dylib 0x0000000112cb2145 start + 1
24 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
最佳答案
该错误是因为您指示目标viewController类是CollectionViewController,但是CollectionViewController没有实现businessName。代替CollectionViewController,您应该指示实现businessName的自定义类。
关于ios - 如何使用Xcode 6从表 View Controller 推送到集合 View Controller ?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31980652/