我想滚动到给定的索引(self.boldRowPath),但是当我scrollToRow之前执行调试时reloadData().
怎么知道reloadData已经完成了?
func getAllTimeEvent() {
self.arrAllTimeEvent = ModelManager.getInstance().getAllTimeEvent(from: self.apportmentDateFrom, to: self.apportmentDateTo)
self.tblTimeEvent.reloadData()
self.tblTimeEvent.scrollToRow(at: self.boldRowPath ?? [0,0], at: .top, animated: true)
}
Run Code Online (Sandbox Code Playgroud)
任何帮助都感激不尽.
我有一个类与本教程的AFHTTPSessionManager组件类似的类http://www.raywenderlich.com/59255/afnetworking-2-0-tutorial
但是,[self.tableView reloadData]对我不起作用.
我有经理如此实施:
-(void) refresh{
manager = [[AFHTTPSessionManager...] iniwithBaseURL:...];
[manager Get:... parameters:... success:^(NSURLSessionDataTask *task, id responseObject){
//test success values in responseObject
if(test){
//Get table data
[self.tableView reloadData];
}
}
....
}
Run Code Online (Sandbox Code Playgroud)
但是如果我之后在一个单独的函数中运行[self.tableView reloadData],它就可以了.为什么会发生这种情况,而不是在教程中应该如何?
我有splitViewController,它具有MasterViewController的一些viewController和DetailViewController的一些tableViewController.当我按下masterViewController上的一个按钮时,我想在detailViewController中显示新的tableViewController而不是现有的.
所以我喜欢这样:
SearchDetailViewController *searchDetailViewController = [[SearchDetailViewController alloc] initWithStyle:UITableViewStylePlain];
UINavigationController *searchDetailNavigationController = [[UINavigationController alloc] initWithRootViewController:searchDetailViewController];
Run Code Online (Sandbox Code Playgroud)
之后,我将数据传递给new tableController中显示:
[searchDetailViewController passInSearchResults:listOfItems];
Run Code Online (Sandbox Code Playgroud)
之后我将"新控制器""推送"到splitViewController:
[searchSplitViewController setViewControllers:[NSArray arrayWithObjects:self.navigationController, searchDetailNavigationController, nil]];
Run Code Online (Sandbox Code Playgroud)
在目标tableViewController方法中传递"passInSearchResults"数据,我也调用reloadData.方法看起来像这样:
- (void)passInSearchResults:(NSMutableDictionary *)searchResults {
self.searchResultList = searchResults;
NSLog(@"Data is passed in: %@",self.searchResultList);
[self.tableView reloadData];
//[self.tableView setNeedsDisplay];
}
Run Code Online (Sandbox Code Playgroud)
控制台:传入数据:[这里我得到了我想要的确切数据,看起来恰到好处].
After this I see that method "numberOfRowsInSection" is fired:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSLog(@"Setting table length: %i",[self.searchResultList count]);
return [self.searchResultList count];
}
Run Code Online (Sandbox Code Playgroud)
控制台:设置表长度:[这里我得到适当的长度]
问题是表没有填充传递的数据,并且没有调用方法"cellForRowAtIndexPath".
怎么可能在reloadData方法"numberOfRowsInSection"被触发但不是方法"cellForRowAtIndexPath"...... ???
谢谢
我想完成这个:
考虑在其标题上带有搜索栏的表格视图.每当搜索字符串时,都会刷新表格视图.
我有2节课
TableViewController(UIViewController子类)
包含UITableView - 显示其表格
从Header类(UIToolBar子类)加载表的标题视图
.
Header(UITableView的标题)
- 包含UISearchBar及其委托
该
UISearchBarDelegates在TableViewController中回调函数
那叫
- (void)reloadSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation
Run Code Online (Sandbox Code Playgroud)
这会导致App崩溃
的函数调用栈帧是如下
[UITableView reloadSections:withRowAnimation:]
[TableViewController functionThatCallsReloadSection]
[Header searchBarSearchButtonClicked:]
Run Code Online (Sandbox Code Playgroud)
reloadSection导致应用程序崩溃.任何想法为什么会这样发生?
是因为在重新加载表视图头时,委托函数仍然在堆栈上处于活动状态?
我没有改变任何与tableview相关的事情(行数或部分数没有变化).我想做的就是重新加载表视图.
编辑:我试图在iPad上做所有这些事情,它提供了一个popover同时使用UISearchDisplayController,我不想使用.我已经有一个表格视图,我想刷新一旦输入文本和搜索按钮被击中,使用搜索代表.唯一的问题是,一旦我在UISearchBar的搜索委托中调用[UITableView reloadSection:](UISearchBar位于我想要重新加载的UITableView的标题上),应用程序崩溃了.
我正在尝试在更新Swift中的数据后重新加载我的表视图,但它似乎不起作用.当我更改选项卡并返回时,表视图会重新加载但不会自动重新加载.这是我的代码:
override func viewDidLoad() {
super.viewDidLoad()
// some code
refresh(self)
}
func refresh(sender: AnyObject) {
// Reload the data
self.tableView.reloadData()
}
Run Code Online (Sandbox Code Playgroud)
我不明白为什么它在Objective-C中工作但在Swift中不起作用...我也尝试过:
dispatch_async(dispatch_get_main_queue(), { () -> Void in
self.tableView.reloadData()
})
Run Code Online (Sandbox Code Playgroud)
因为我在其他帖子中看到了这个,但它也不起作用.
谢谢你的帮助
编辑:我的整个视图控制器
class HighwaysViewController: UITableViewController {
var highways: [Highway]!
override func viewDidLoad() {
super.viewDidLoad()
// Uncomment the following line to preserve selection between presentations
// self.clearsSelectionOnViewWillAppear = false
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = …Run Code Online (Sandbox Code Playgroud) 我有一个单独的线程创建一个UIView对象,将其插入UITableView的数据源,然后在UITableView上调用reloadData.但是,由于它是一个单独的线程,它不能直接调用reloadData,它需要让mainthread执行它...但是你怎么告诉mainthread这样做呢?
谢谢
我正在使用a UICollectionView来显示场上不同位置的球员.每个单元格都包含显示玩家姓名和位置名称的标签.视图中的位置由自定义布局确定,该布局从数据源读取位置信息...即,字段上的位置与数据源中的索引无关,如在流布局中.对于各种位置,单元格也有点不同......'cellForItemAtIndexPath'根据位置从各种重用标识符中进行选择.
我希望用户能够在位置上交换玩家.只要我更新集合视图数据源并调用,一切都可以正常工作[self.collectionView reloadData].但我想动画单元格的交换,以便用户可以看到更改.我正在使用此代码,其中inboundSourceIndex和outboundSourceIndex先前已设置为交换的项目:
[self.collectionView performBatchUpdates:^{
[self.collectionView moveItemAtIndexPath:inboundOriginIndex toIndexPath:outboundOriginIndex];
[self.collectionView moveItemAtIndexPath:outboundOriginIndex toIndexPath:inboundOriginIndex];
} completion:nil];
}
[self assignmentsUpdate]; // This method updates the data source for the collection view
[self.collectionView.collectionViewLayout invalidateLayout];
[self.collectionView reloadData];
Run Code Online (Sandbox Code Playgroud)
插入批量更新后,我得到所需的单元格动画,它们之间相互交换,播放器名称标签显示正确,并且布局为单元格提供了正确的帧(可能会有所不同).但其他一切都很混乱:位置标签没有更新,并且单元格没有使用正确的重用标识符重新加载 - 就像collectionView没有真正调用一样cellForItemAtIndexPath.我已经尝试更改数据更新和reloadData的顺序,但无济于事.我可以看到移动的细胞可能暂时改变indexPaths,但的CollectionView怎么看待错误后,我打电话invalidateLayout和reloadData?是不是基于数据源从头开始构建视图?
batch-updates reloaddata ios uicollectionview uicollectionviewlayout
我实现了一个UITableView带有更多功能的负载.tableView从有时很慢的服务器加载大图像.我正在为每个图像启动一个URLConnection并重新加载对应于URLConnection的indexPath(与连接对象一起保存).连接本身调用-reloadDatatableView.
现在,当单击加载更多按钮时,我滚动到位置底部的新数据集的第一行.这很好用,也是我的异步加载系统.
我面临以下问题:当连接"太快"时,tableView正在重新加载给定indexPath的数据,而tableView仍然滚动到新数据集的第一个单元格,tableView向后滚动一半的高度细胞.
这应该是它应该是什么样子以及它实际上做了什么:

^^^^^^^^^^^^ should ^^^^^^^^^^^^ ^^^^^^^^^^^^^ does ^^^^^^^^^^^^^
以下是一些代码:
[[self tableView] beginUpdates];
for (NSMutableDictionary *post in object) {
[_dataSource addObject:post];
[[self tableView] insertRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:[_dataSource indexOfObject:post] inSection:0]] withRowAnimation:UITableViewRowAnimationBottom];
}
[[self tableView] endUpdates];
[[self tableView] scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:[_dataSource indexOfObject:[object firstObject]] inSection:0] atScrollPosition:UITableViewScrollPositionBottom animated:YES];
Run Code Online (Sandbox Code Playgroud)
-tableView:cellForRowAtIndexPath:如果数据源数组中的对象是字符串,则启动JWURLConnection,并将其替换UIImage为完成块中的实例.然后它重新加载给定的单元格:
id image = [post objectForKey:@"thumbnail_image"];
if ([image isKindOfClass:[NSString class]]) {
JWURLConnection *connection = [JWURLConnection connectionWithGETRequestToURL:[NSURL URLWithString:image] delegate:nil startImmediately:NO];
[connection setFinished:^(NSData *data, NSStringEncoding encoding) {
[post setObject:[UIImage imageWithData:data] forKey:@"thumbnail_image"]; …Run Code Online (Sandbox Code Playgroud) 我有一个自定义单元格的tableView.
我还有一个针对这个custrom单元的.swift文件.
在这个文件中,我有一个函数,它没有发送者:AnyObject输入参数.
如何从此函数调用tableView.reloadData()?
我对此很陌生.我花了几个小时来讨论关于这个主题的各种问题,但找不到适合我问题的答案.
我有一个viewcontroller(不是tableviewcontroller)与tableview作为子视图.我的问题是如何在视图控制器的:viewwillappear方法中重新加载表数据.在方法内部,我无法"访问"tableview实例.(另外我理解我不能使用reloaddata()因为我不使用tableviewcontroller).
你知道任何简单的解决方案吗?(我非常假设一个协议可以帮助吗?)
这是简短的代码:
class ViewController3: UIViewController, UITableViewDataSource, UITableViewDelegate {
var Person_data = [Person]()
override func viewDidLoad() {
super.viewDidLoad()
let tb: UITableView = UITableView(frame: CGRect(x: 10, y: 50, width: 200, height:600), style: UITableViewStyle.Plain)
tb.dataSource = self
tb.delegate = self
super.view.addSubview(tb)
fetch_data()
}
func tableView(tableview: UITableView, numberOfRowsInSection section: Int) -> Int {
let rows = Person_data.count
return rows
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
let cell: UITableViewCell = UITableViewCell()
cell.textLabel?.text = Person_data[indexPath.row].name
return cell
}
override func …Run Code Online (Sandbox Code Playgroud) reloaddata ×10
uitableview ×8
ios ×7
swift ×4
objective-c ×2
afnetworking ×1
custom-cell ×1
iphone ×1
tableview ×1
uisearchbar ×1
uiview ×1