目标c:将委托移交给其他班级
我在这里遇到了一个问题。我有一个协议,它规定了一个方法,该方法返回我的表视图的数据源。数据源由一个类生成,用于 3 个表视图。如果您点击一个单元格,您将进入下一个具有不同来源的表格视图,依此类推(我想您明白了)。
对于第一个表视图,一切正常,但是当我将删除移交给下一个表视图时,我仍然没有获得第二个表视图的数据源。我是否必须在某个时刻释放委托?如果必须的话,当点击导航栏按钮项时,如何取回它......?
如果你有什么想法请告诉我。
编辑:
if ([Where isEqualToString:@"System"])
{
if ([exchangeDelegate respondsToSelector:@selector(getNewDataSourceForSystem:)])
{
[exchangeDelegate getNewDataSourceForSystem: [controlDelegate setBranchNavigation:What]];
}
}
else if ([Where isEqualToString:@"User"])
{
if ([exchangeDelegate respondsToSelector:@selector(getNewDataSourceForUser:)])
{
[exchangeDelegate getNewDataSourceForUser: [controlDelegate setLeafNavigation:What]];
}
}
if ([exchangeDelegate respondsToSelector:@selector(getNewDataSourceForCostumer:)])
{
[exchangeDelegate getNewDataSourceForCostumer: [controlDelegate setRootNavigation]];
}
每个 respondToSelector 进入不同的类。
编辑: * 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[Costumers getNewDataSourceForSystem:]: 无法识别的选择器发送到实例 0x8a3b0e0”
这就是当我省略 respondsToSelector 时得到的异常:@选择器
。
I am here confronted with a certain problem. I have a protocol which states a method, that returns the datasource for my tableviews. The datasources are generated by one class, for 3 tableviews. If you tap on one cell, you get to the next tableview with a different source and so on (I think you get the point).
Everything works fine for the first tableview, but as I hand over the deletage to the next tableview I still do not get the datasource for the second. Do I have to release the delegate at a certain point? And if I have to, how do I get it back, when the navigationbarbuttonitem is tapped on...?
Tell me if you have any ideas.
EDIT:
if ([Where isEqualToString:@"System"])
{
if ([exchangeDelegate respondsToSelector:@selector(getNewDataSourceForSystem:)])
{
[exchangeDelegate getNewDataSourceForSystem: [controlDelegate setBranchNavigation:What]];
}
}
else if ([Where isEqualToString:@"User"])
{
if ([exchangeDelegate respondsToSelector:@selector(getNewDataSourceForUser:)])
{
[exchangeDelegate getNewDataSourceForUser: [controlDelegate setLeafNavigation:What]];
}
}
if ([exchangeDelegate respondsToSelector:@selector(getNewDataSourceForCostumer:)])
{
[exchangeDelegate getNewDataSourceForCostumer: [controlDelegate setRootNavigation]];
}
each respondToSelector goes to a different class.
EDIT:
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Costumers getNewDataSourceForSystem:]: unrecognized selector sent to instance 0x8a3b0e0'
Thats what I get as an exception when I leave out respondsToSelector:@selector
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否已调用
-[UITableView reloadData]
来通知其当前状态失效?您是否重载了委托 setter 方法,以便根据需要获取和设置新的数据源和委托?大概是这样的:
Have you called
-[UITableView reloadData]
to inform it about invalidation of its current state?And have you overloaded you delegate setter method in order to also fetch and set the new datasource and delegate as needed? Probably something like this:
因此,看起来,使用单例是为我的视图存储数据的正确方法:
就这么简单......谢谢你们的灵感:-)
So, as it seems, using a singleton is the proper way to store my data for my views:
As simple as it is ... thank you guys for your inspiration :-)