gpt4 book ai didi

ios - 如何使用 xcode 6 从 TableView Controller 推送到 Collection View Controller ?

转载 作者:行者123 更新时间:2023-11-28 18:56:31 28 4
gpt4 key购买 nike

  • 我正在使用 Xcode 6 制作该应用程序。我有两个 TableView Controller ,Root 和 Second,现在我想从 Second 传递数据 TableView Controller 到 Collection View Controller 。我添加了一个segue 但有一个异常(exception)。不确定我哪里出错了。

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", nil];

       relToMe = [NSArray arrayWithObjects:@"IDEA2",@"NEW",@"IN VAL...",@"IN ESTI...",@"READY...",@"APPROV...",@"IT

CHAN...",@"UNDER...",@"IMPLEM",@"CLOSED", nil];

       repByMe = [NSArray arrayWithObjects:@"IDEA3",@"NEW",@"IN VAL...",@"IN ESTI...",@"READY...",@"APPROV...",@"IT

CHAN...",@"UNDER...",@"IMPLEM",@"CLOSED", nil];

       redForApp = [NSArray arrayWithObjects:@"IDEA4",@"NEW",@"IN VAL...",@"IN ESTI...",@"READY...",@"APPROV...",@"IT

CHAN...",@"UNDER...",@"IMPLEM",@"CLOSED", nil];

       appBC = [NSArray arrayWithObjects:@"IDEA5",@"NEW",@"IN VAL...",@"IN ESTI...",@"READY...",@"APPROV...",@"IT

CHAN...",@"UNDER...",@"IMPLEM",@"CLOSED", nil];

       // 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)发件人{

   return NO;

}



- (void)collectionView:(UICollectionView *)collectionView performAction:(SEL)action forItemAtIndexPath:(NSIndexPath *)indexPath

withSender:(id)发件人{

   }

*/



@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", nil];

       relToMe = [NSArray arrayWithObjects:@"IDEA2",@"NEW",@"IN VAL...",@"IN ESTI...",@"READY...",@"APPROV...",@"IT

CHAN...",@"UNDER...",@"IMPLEM",@"CLOSED", nil];

       repByMe = [NSArray arrayWithObjects:@"IDEA3",@"NEW",@"IN VAL...",@"IN ESTI...",@"READY...",@"APPROV...",@"IT

CHAN...",@"UNDER...",@"IMPLEM",@"CLOSED", nil];

       redForApp = [NSArray arrayWithObjects:@"IDEA4",@"NEW",@"IN VAL...",@"IN ESTI...",@"READY...",@"APPROV...",@"IT

CHAN...",@"UNDER...",@"IMPLEM",@"CLOSED", nil];

       appBC = [NSArray arrayWithObjects:@"IDEA5",@"NEW",@"IN VAL...",@"IN ESTI...",@"READY...",@"APPROV...",@"IT

CHAN...",@"UNDER...",@"IMPLEM",@"CLOSED", nil];

   }



- (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

重用标识符:简单表标识符];

       }

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

最佳答案

-[UICollectionViewCell bcRequestLabel] unrecognized selector sent to instance…

您正在访问 UICollectionViewCellbcRequestLabel,它不存在。

确保您在 Storyboard的 Collection View 单元格中正确设置了自定义类。

关于ios - 如何使用 xcode 6 从 TableView Controller 推送到 Collection View Controller ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31980652/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com