我有这个Segue公司在这里:Objective-C的问题与Segue公司
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:@"showDetail"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
//NSDate *object = self.objects[indexPath.row];
NSString *strPOIndex = [self.tableData[indexPath.row] valueForKey:@"POIndex"];
LHPurchaseOrderDetail *controller = (LHPurchaseOrderDetail *)[[segue destinationViewController] topViewController];
[controller setDetailItem:strPOIndex];
controller.navigationItem.leftBarButtonItem = self.splitViewController.displayModeButtonItem;
controller.navigationItem.leftItemsSupplementBackButton = YES;
}
}
和我试图用它做的是通过strPOIndex从我的主控制器我的详细控制器setDetailItem ..但是当我运行这个,我得到一个错误:
-[LHPurchaseOrderMaster setDetailItem:]: unrecognized selector sent to instance 0x156cce80
我不明白为什么会发生这种情况,这是我的故事板的问题?或我的主控制器或细节控制器?这里是我的详细信息控制器:
.H:
#import <UIKit/UIKit.h>
@interface LHPurchaseOrderDetail : UIViewController
@property (strong, nonatomic) IBOutlet UINavigationBar *NavBar;
@property (strong, nonatomic) id detailItem;
@property (weak, nonatomic) IBOutlet UILabel *detailDescriptionLabel;
@end
.M:
#import "LHPurchaseOrderDetail.h"
@interface LHPurchaseOrderDetail()
@end
@implementation LHPurchaseOrderDetail
- (void)setDetailItem:(id)newDetailItem {
if (_detailItem != newDetailItem) {
_detailItem = newDetailItem;
// Update the view.
[self configureView];
}
}
- (void)configureView {
// Update the user interface for the detail item.
if (self.detailItem) {
self.detailDescriptionLabel.text = [self.detailItem description];
}
}
- (void)viewDidLoad {
[super viewDidLoad];
[self configureView];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
@end
主控制器:
.H
#import <UIKit/UIKit.h>
#import "ShinobiDataSource.h"
#import "PopupGenerator.h"
@class LHPurchaseOrderDetail;
@interface LHPurchaseOrderMaster : UITableViewController<UIPopoverControllerDelegate, UIPickerViewDelegate>
@property (strong, nonatomic) IBOutlet UIButton *communityBtn;
@property (strong, nonatomic) IBOutlet UIButton *lotBtn;
@property (strong, nonatomic) IBOutlet UIButton *goBtn;
- (IBAction)communityBtnPressed:(id)sender;
- (IBAction)lotBtnPressed:(id)sender;
- (IBAction)goBtnPressed:(id)sender;
@property(nonatomic, retain) NSArray * tableData;
@property (strong, nonatomic) LHPurchaseOrderDetail *purchaseOrderController;
@end
你确定topViewController是LHPurchaseOrderDetail类型吗?尝试调试线路,看看返回的真实类型 – giorashc
您是否尝试过使用'LHPurchaseOrderDetail * controller =(LHPurchaseOrderDetail *)[segue destinationViewController];'!?你为什么要访问'topViewController'属性? – luk2302
@ luk2302我想他正在访问'topViewController'属性,因为他的UIViewController嵌入在UINavigationController中,并且segue对应于navigationController(因此为cast)。 – Razvan