gpt4 book ai didi

objective-c - 多次用新数据刷新 NSTableView

转载 作者:搜寻专家 更新时间:2023-10-30 19:47:17 24 4
gpt4 key购买 nike

我有一个 NSMutableArray 并从中加载我的 tableview。现在我在 UI 中有一个按钮,它可以让用户多次刷新进入数组的数据。每当 Array 中有新数据时,我都想刷新 tableView。更新数组后只做 [tableView reloadData] 似乎会引发沙滩球。关于实现此目标的好方法有什么想法吗?

此外,我一直在研究绑定(bind)作为从数组实现我的 NSTableView 的一种方式,但是在线显示的所有示例在他们想要将数据添加到他们的表时都使用绑定(bind)?谁能告诉我如何使用绑定(bind)将包含数据的数组加载到 tableView 中?

抱歉,如果问题是菜鸟问题,如果有人能指出正确的数据,我愿意阅读。谢谢 :)(我不是在寻找捷径,只是想从有经验的人那里获得一些关于如何处理这些事情的学习建议)

-(IBAction)refreshList:(id)sender
{
//setup array here and sort the array based on one column. This column has
identifier 'col1' and it works as expected


[aTable reloadData];
}

- (int) numberOfRowsInTableView:(NSTableView *)aTable
{ // return count of array
}

- (id)tableView:(NSTableView *)aTable objectValueForTableColumn: (NSTableColumn *)
tableColumn row:(int)row
{
//set up arrays here to load data in each column


}
- (void)tableView:(NSTableView *)aTableView sortDescriptorsDidChange:(NSArray
*)oldDescriptors
{
//sort here when column headers are clicked
}

-(IBAction)autorefresh:(id)sender
{

// Here i am trying to reload the array and refresh the tableView. I want to
constantly keep refreshing the array and loading the tableView here. The array does
get refreshed but I am having trouble loading the tableView.


for ( int i =0; i<=2;i++)
{
// reload the array with data first.
[aTable reloadData];
i = 1;

}

最佳答案

使用该代码(尤其是您非常新颖的“while true”循环),您会得到一个沙滩球,因为您永远不会回到 man run-loop。要在设置 NSTableView 后使用这样的代码来修复,它将每 1.0 秒运行一次

NSTimer* timer = [NSTimer timerWithTimeInterval:1.0
target:[NSApp delegate]
selector:@selector(myReloadData:)
userInfo:nil
repeats:YES];

[[NSRunLoop mainRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode];

然后在您的应用委托(delegate)中创建 myReloadData

- (void)reloadMyData:(NSTimer*)ntp
{
// reload the array with data first.
[aTable reloadData];
}

关于objective-c - 多次用新数据刷新 NSTableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2038915/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com