0
我在(NewsDetailsVC.swift)中有一個自定義委託,其中必須將選定表格單元格文本傳遞給另一個類(MainNewsVC.m),這是一個目標c類。從目標c類調用swift類的自定義委託引發錯誤
NewsDetailsVC.swift
@objc protocol SelectedDataDelegate {
func valuePassed(dataString: String)
}
class NewsDetailsViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
weak var newsPageDelegate: SelectedDataDelegate?
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
let selectedCell = tableView.cellForRow(at: indexPath)
let storyboard = UIStoryboard(name: "MainNewsPage", bundle: nil)
mainVC = storyboard.instantiateViewController(withIdentifier: "MainNews") as! MainNewsViewController
mainVC.passedValue = selectedCell?.textLabel?.text
print("text label value: ", mainVC.passedValue)
newsPageDelegate?.valuePassed(dataString: mainVC.passedValue)
print("text from delegates: ", (dataString: mainVC.passedValue))
}
MainNewsVC.h
@protocol SelectedDataDelegate <NSObject>
@end
@interface MainNewsViewController : UIViewController<UITextFieldDelegate,UIScrollViewDelegate, SelectedDataDelegate > {
NSString *newsValue;
BOOL isFromSelection;
}
@property (nonatomic, assign) id <SelectedDataDelegate> receiveNewsDelegate;
-(void)valueChanged:(NSString *)newsString delegate:(id<SelectedDataDelegate>)theDelegate;
MainNewsVC.m
@synthesize receiveNewsDelegate;
-(void)selectQuestion:(UITapGestureRecognizer *) sender
{
CGPoint touchLocation = [sender locationOfTouch:0 inView:newsTable];
newIndexPath = [newsTable indexPathForRowAtPoint:touchLocation];
newsDetailsVC = [NewsDetailsViewController instantiate];
newsDetailsVC.SelectedDataDelegate = self;
[self presentViewController:selectQuestionVC animated:YES completion:nil];
}
-(void) valuePassed:(NSString *)newsString receiveNewsDelegate:(id<SelectedDataDelegate>)theDelegate {
[newsTable reloadData];
newsValue = newsString;
NSLog(@"newsValue: %@", newsValue);
isFromSelection = YES;
self.receiveNewsDelegate = theDelegate;
[newsTable reloadData];
}
在上述方法中,當我試圖自該自定義委託我收到誤差作爲「在'NewsDetailsViewController *'類型的對象上找不到」Property'SelectedDataDelegate'「。上述代碼的任何問題?