У меня есть две кнопки в нижнем колонтитуле пользовательского макета collectionView. Я хочу передать indexPath нижнего колонтитула в класс назначенияView, когда пользователь нажимает кнопку. Я написал свой код обычным способом, который мне удавался раньше. Однако по какой-то причине всякий раз, когда я нажимаю кнопку, он вылетает.
Я пробовал разные подходы для каждой кнопки, чтобы выполнить эту работу, но ни один из них не работал. Я установил класс назначенияView в правильный класс в раскадровке. Пожалуйста, помогите мне. Любая помощь с примером кода будет очень признательна, так как английский не мой родной язык. Спасибо.
Вот мой код
// perform segue passing indexPath information
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// approach 1 : pass dictionary
if([[segue identifier] isEqualToString:@"SeeAllPictures"]) {
Footer *footerView = (Footer *)((UIButton *)sender).superview;
// debug code : working well
NSLog(@"perform segue from indexpath {%ld - %ld}", (long) footerView.indexPath.section, (long) footerView.indexPath.row);
SeeAllPicture *destVC = (SeeAllPicture *)[segue destinationViewController];
NSDictionary *indexPathDic = @{@"key1":footerView.indexPath};
// crashes at below line
destVC.indexPathDic = indexPathDic;
}
// approach 2 : pass indexPath.section, the NSInteger value
else if([[segue identifier] isEqualToString:@"GoToDiary"]) {
Footer *footerView = (Footer *)((UIButton *)sender).superview;
// debug code : working well
NSLog(@"perform segue from indexpath {%ld - %ld}", (long) footerView.indexPath.section, (long) footerView.indexPath.row);
Diary *destVC = (Diary *)[segue destinationViewController];
// crashes at below line
destVC.section = footerView.indexPath.section;
}
}
ниже заголовок одного из классов назначения
#import <UIKit/UIKit.h>
@interface SeeAllPicture : UIViewController
@property (strong, nonatomic) IBOutlet UILabel *titleLabel;
@property (strong, nonatomic) NSDictionary *indexPathDic;
@property NSInteger section;
@end
И это сообщение, когда мое приложение вылетает
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UINavigationController setIndexPathDic:]: unrecognized selector sent to instance 0x7ff8c8c4f140'
*** First throw call stack:
(
0 CoreFoundation 0x000000010f7f7a75 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010f490bb7 objc_exception_throw + 45
2 CoreFoundation 0x000000010f7fed1d - [NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x000000010f7569dc ___forwarding___ + 988
4 CoreFoundation 0x000000010f756578 _CF_forwarding_prep_0 + 120
5 InfanTree 0x000000010ea1113b - [ViewController prepareForSegue:sender:] + 635
6 UIKit 0x000000011037e3cc - [UIStoryboardSegueTemplate _perform:] + 151
7 UIKit 0x000000010fe2ba22 - [UIApplication sendAction:to:from:forEvent:] + 75
8 UIKit 0x000000010ff32e50 -[UIControl _sendActionsForEvents:withEvent:] + 467
9 UIKit 0x000000010ff3221f -[UIControl touchesEnded:withEvent:] + 522
10 UIKit 0x00000001101d9e80 _UIGestureRecognizerUpdate + 9487
11 UIKit 0x000000010fe71856 -[UIWindow _sendGesturesForEvent:] + 1041
12 UIKit 0x000000010fe72483 -[UIWindow sendEvent:] + 667
13 UIKit 0x000000010fe3efb1 - [UIApplication sendEvent:] + 246
14 UIKit 0x000000010fe4c227 _UIApplicationHandleEventFromQueueEvent + 17700
15 UIKit 0x000000010fe2723c _UIApplicationHandleEventQueue + 2066
16 CoreFoundation 0x000000010f72cc91 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
17 CoreFoundation 0x000000010f722b5d __CFRunLoopDoSources0 + 269
18 CoreFoundation 0x000000010f722194 __CFRunLoopRun + 868
19 CoreFoundation 0x000000010f721bc6 CFRunLoopRunSpecific + 470
20 GraphicsServices 0x0000000112950a58 GSEventRunModal + 161
21 UIKit 0x000000010fe2a580 UIApplicationMain + 1282
22 InfanTree 0x000000010ea1b7c3 main + 115
23 libdyld.dylib 0x0000000113211145 start + 1
)
UINavigationController *nav = segue.destinationViewController; SeeAllPicture *destVC = nav.topViewController;
- person rdelmar   schedule 23.04.2015