Reputation:
i have created protocol in swift use in objective c file but protocol method does not called here is code
@Swift file
@objc protocol clickBookmarksProtocolDelegate
{
func openbook(bookmark : String)
}
var delegate : clickBookmarksProtocolDelegate?
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
a = data[indexPath.row][main]
println(a)
if (a == "Bookmarks")
{
self.delegate?.openbook(data[indexPath.row][url])
dismissViewControllerAnimated(false, completion: nil)
}
@obj C .m file
#import "Video_Downloader-Swift.h"
@interface BrowserViewController() <clickBookmarksProtocolDelegate>
@end
- (void)openbook:(NSString * __nonnull)bookmark
{
[self loadAddress:bookmark];
_addressBar.text=bookmark;
}
Method does not call
Upvotes: 1
Views: 318
Reputation: 9144
Well, you shouldn't use delegate for this. Delegates are used like some sort of a callback. For instance imagine you have a controller that will show another one:
FirstViewController -> SecondViewController
Delegates, are used in this case when your SecondViewController wants to call the FirstViewController.
In your case you just want to display SecondViewController, for this you have a few options.
The simplest if you have a navigation view controller is to push the new BrowserViewController in your didSelectCell method:
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
self.navigationController?.pushViewController(BrowserViewController(), animated: true)
}
Upvotes: 1