简体   繁体   English

什么时候调用cellForRowAtIndexPath?

[英]When is cellForRowAtIndexPath called?

I have a tableview in my app...The contents of this list view are displayed based on ext API dynamic search... 我的应用程序中有一个tableview ...此列表视图的内容基于ext API动态搜索显示...

eg If I type "G" in searchbar it will display GA, GB, GC1, GC2, GC3,.. 例如,如果我在搜索栏中键入“ G”,它将显示GA,GB,GC1,GC2,GC3等。

if I now change to GC, it will only display GC1, GC2, GC3.. 如果我现在更改为GC,它将仅显示GC1,GC2,GC3。

I am storing the items in an array.. 我将项目存储在数组中。

My question is how do I ensure that what the user is typing and seeing as search results are synchronized..I mean if he clicks on GC1 in list view, he should see GC1's detail and not other's.. 我的问题是如何确保用户输入的内容以及搜索结果的同步性。.我的意思是,如果他在列表视图中单击GC1,则应该看到GC1的详细信息,而不是其他的详细信息。

Also when is cellForRowAtIndexPath called so that I can update the array each time user types in searchbar? 另外,何时调用cellForRowAtIndexPath以便每次用户在搜索栏中键入内容时都可以更新数组?

-cellForRowAtIndexPath: is sent by the table anytime it wants a cell to display, such as when the table is redrawn, or when a new cell is needed because the user scrolled a bit. -cellForRowAtIndexPath:由表在它想要显示单元格的任何时间发送,例如在重绘表或由于用户滚动而需要新单元格时。

You can force the table to update its contents by calling [table reloadData], if 'table' is a pointer to your table. 如果'table'是指向表的指针,则可以通过调用[table reloadData]来强制表更新其内容。

You should be updating your array of filtered items in the filterContentForSearchText: scope: method. 您应该在filterContentForSearchText: scope:方法中更新已过滤项目的数组。 There is another method, searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString that will be called when the user types in the search bar. 还有另一种方法searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString ,当用户在搜索栏中键入内容时将被调用。 If you return YES from this method, then the table will be reloaded, which causes cellForRowAtIndexPath: to be called. 如果从此方法返回YES,则将重新装入表,这将导致调用cellForRowAtIndexPath:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM