Chinese readers annotation:這個(gè)問題google,stackoverflow,github都還沒有相關(guān)資料,所以把內(nèi)容寫成英文的,以便于幫助國外的朋友。
English readers annotation:This problem has not been found by google or stackoverflow or github yet. So I writed it at here so that you could get help from this.(By the way, I am a Chinese)
I want to use rac_signalForSelector to observe the UITableView's delegate so I could let the dataDelegate and delegate being reused from a independent class. So If they have the same cell, I would not need to implement them triples.
If you use the RAC(which means ReactiveCocoa), Firstly come into you head is a code sample like this:
well...It's fine if you don't need this method:
"), So I have work around with it, and I guessed it's the reason of swift Protocol isn't a NSObject(you could see from UIScrollViewDelegate's declaration).
By a chance I found there is a method named 'NSProtocolFromString' and RAC provided a method
So I combined them both
It doesn't crash any more and the function of my design worked fine. So, that's the way! done!
Hope this helps you out, it's really struggle.
English readers annotation:This problem has not been found by google or stackoverflow or github yet. So I writed it at here so that you could get help from this.(By the way, I am a Chinese)
I want to use rac_signalForSelector to observe the UITableView's delegate so I could let the dataDelegate and delegate being reused from a independent class. So If they have the same cell, I would not need to implement them triples.
If you use the RAC(which means ReactiveCocoa), Firstly come into you head is a code sample like this:
self.rac_signalForSelector(Selector("scrollViewDidEndDecelerating:")).subscribeNext{ _ in
self.setTabBarVisiable(false, animated:true)
}
scrollView.delegate = self
self.setTabBarVisiable(false, animated:true)
}
scrollView.delegate = self
well...It's fine if you don't need this method:
self.rac_signalForSelector("scrollViewDidEndDragging:willDecelerate:").subscribeNext{ _ in
self.setTabBarVisiable(false, animated:true)
}
But if you do, you will get a crash message(EXE_BAD_ACCESS) which caused by the RAC.It means RAC can't find a method form string '@' (which should be @"scrollViewDidEndDragging:willDecelerate:self.setTabBarVisiable(false, animated:true)
}
"), So I have work around with it, and I guessed it's the reason of swift Protocol isn't a NSObject(you could see from UIScrollViewDelegate's declaration).
By a chance I found there is a method named 'NSProtocolFromString' and RAC provided a method
- (RACSignal *)rac_signalForSelector:(SEL)selector fromProtocol:(Protocol *)protocol;
So I combined them both
self.rac_signalForSelector("scrollViewDidEndDragging:willDecelerate:",
fromProtocol:NSProtocolFromString("UITableViewDelegate")).subscribeNext{ _ in
self.setTabBarVisiable(false, animated:true)
}
fromProtocol:NSProtocolFromString("UITableViewDelegate")).subscribeNext{ _ in
self.setTabBarVisiable(false, animated:true)
}
It doesn't crash any more and the function of my design worked fine. So, that's the way! done!
Hope this helps you out, it's really struggle.
