回答
创建ResponseDelegate
协议
protocol ResponseDelegate {
func didReceiveResponse(data:AnyObject?)
}
在插座类
class SocketClass {
var responseDelegate:ResponseDelegate //This should be implemented and referred to your ViewController
func getCurrentAmount() {
[socket on:@"currentAmount" callback:^(NSArray* data, SocketAckEmitter* ack) {
responseDelegate.didReceiveResponse(data)
}
}
}
对您的委托引用在你ViewController
//Set your delegate here
socketClassObject.responseDelegate = self
func didReceiveResponse(data:AnyObject) {
println("Recieved data:\(data)")
}
使用NSNotificationsCentre
在你的ViewController
//Subscribe/Listen for the events
NSNotificationCenter.defaultCenter().addObserver(self, selector: "didReceiveResponse:", name:"CurrentAmountNotification", object: nil)
func didReceiveResponse(notification: NSNotification) {
println("Recieved data:\(notification.userInfo)")
}
在你SocketClass
class SocketClass {
func getCurrentAmount() {
[socket on:@"currentAmount" callback:^(NSArray* data, SocketAckEmitter* ack) {
NSNotificationCenter.defaultCenter().postNotificationName("CurrentAmountNotification", object: nil, userInfo:data)
}
}
}
我使用NSNotificationsCenter 什么是您的解决方案和NSNotificationsCenter之间不同的时候传球 –
更新我的答案做到这一点NSNotifications的方式,它更多的是一个设计决定,代表主要用于1:1的关系和NSNotifications 1:N,这取决于你在找什么。如果多个类正在使用SocketClass,那么请去NSNotifications。 –
你得给SEGUE在故事板的标识符。(说vs_segue)
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?){....}
是要求所有塞格斯被称为表格当前的UIViewController。因此,标识是区分不同塞格斯
然后使用此代码:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "vs_segue" {
var nextScene = segue.destinationViewController as! VehicleDetailsTableViewController
// Pass the selected object to the new view controller.
nextScene.currentObjectInNextScreen = selectedObjectWhichYouHave
}
}
广场VAR nextScene后一个破发点,看看它是否正在对点击/更改视图控制器触发。如果不是,那么故事板中提供的标识符名称必须与此处给出的名称不同。
谢谢
快乐编码。
如果我在某些视图控制器是和recive数据IO 我想通过这些数据来查看控制器 –
- 1. 班“的ViewController”在迅速
- 2. 将数据传递迅速的UIViewController 3
- 3. 迅速改变球员
- 4. 传递参数在迅速
- 5. 得到一类变量数据 - 迅速
- 6. 什么是(ViewController *)self.presentingViewController;在迅速?
- 7. 创建一个球体的iOS迅速
- 8. 类型“的ViewController”不符合协议“UIDocumentPickerDelegate”迅速2
- 9. 解析数据迅速
- 10. 打印数据迅速
- 11. 搜索数据,并迅速
- 12. 迅速SpriteKit SKNode类
- 13. 迅速改变球类型的颜色2
- 14. 添加字符串数组在酥料饼的ViewController在迅速
- 15. 子类的UIView在迅速
- 16. 迅速gzip的数据串的问题
- 17. 迅速IOS数据持久性的UIImage
- 18. 从ViewController B传递数据到ViewController A
- 19. 迅速类作为参数,而.self
- 20. 为迅速范围类型
- 21. 子类在IOS迅速
- 22. 迅速
- 23. 迅速
- 24. 迅速从数据透视表
- 25. Firebase +迅速检索用户数据
- 26. 保存XML数据响应[迅速]
- 27. 迅速火力检索数据错误
- 28. 滚动以加载数据。迅速。 UITableView
- 29. 夫特+核心数据:无法迅速
- 30. 的迅速
我假设你正在使用套接字-io的客户端IOS。如果您正在接收响应并将数据设置为响应块中的某个对象,是不是直接将数据发布到所有侦听器?你能详细说明你做了什么以及你在找什么吗? –
我想从插座recived直接从插座视图控制器 –