UISearch 重新排列indexpath.row
我在 TableView
中实现了一个 UiSearchBar
,并且还有两个 NSArray
,一个用于标题,一个用于描述。当我搜索标题数组时,它会返回正确的搜索,但是当我单击搜索附带的行时,如果单击第一行,我会得到“第 0 行”。我的问题是如何在两个数组之间建立连接,以便当搜索根据用户搜索重新排列标题时,描述数组对应于标题所在的同一行。
I have a UiSearchBar
implemented in my TableView
, and I also have two NSArray
s, one for title and one for description. When I search through the array of the titles, it returns the right search, but when I click on a row that the search came with, I get "row 0" if I click on the first row. My question is how to make a connection between the two arrays so that when the search rearranges the titles based on the user search, the description array corresponds to the same row the title is at.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
只需不要使用两个
NSArray
,而只使用一个带有自定义NSObject
对象的 NSArray:然后您将所有信息存储在一个类中,这就是 Obj-C 的方式。您可以轻松地执行搜索,因为对象本身有点知道它是否与给定的关键字匹配,因此当您想要更改
SomeObject
时,您可以轻松地管理这些更改班级本身。Simply do not use two
NSArray
s, but just one with customNSObject
objects:Then you have all your information stored in one class, the way Obj-C is meant to be. You can easily perform the search because the objects itself sort of knows whether it matches a given keyword, so when you'd like to change
SomeObject
you can easily manage those changes in the class itself.我确实将两个数组合并为一个,但这使得 tableviewcell 加载速度变慢,因为单元格同时保存了标题和描述
I did merge the two arrays into one, but that made the tableviewcell load alot slower because the cell is holding both, the title and description
我曾经遇到过这个问题所以为了快速解决我这样做:
在标题中:
BOOL 使用FilterArray;
在完整字典和过滤字典之间切换时,只需将上面的 BOOL 分别设置为 NO 和 YES 即可。
然后在 didSelectRowAtIndexPath 中使用“if”语句来检查 usingFilterArray 的状态。
休息应该很轻松。 (如果您仍然需要帮助,请告诉我)
只有一件事是,当您在过滤器字典水合后执行搜索时,如果您取消搜索,则需要确保运行此搜索,否则您的应用程序将崩溃,因为水合字典中不会有任何对象。 (我假设你清理了过滤后的字典)
伙计,这只是一个快速修复。
I had this problem once So for the quick fix I did this:
In the header:
BOOL usingFilterArray;
Where you switch between the complete dictionary and the filtered one simply set the above BOOL to NO and YES respectively.
then in didSelectRowAtIndexPath use "if" statement to check the sate of the usingFilterArray.
Rest should be pretty easy. (Let me know if you still need help)
Just one thing when you perform the search after the filter Dictionary is hydrated if you cancel the search you need to make sure to run this or your app is going to crash as the hydrated dictionary will not have any object in it. (I assumed you cleaned the filtered Dictionary)
Mate this is just a quick fix.