NSTableView not updating like I think it should

被刻印的时光 ゝ 提交于 2020-01-07 07:42:49

问题


I have the following code:

- (void)updateServerList {

    [crazyStuff reloadData];
    NSLog(@"Hi");

}

- (int)numberOfRowsInTableView:(NSTableView *)tableView
{
    NSLog(@"Numbers have Changed");
    return [serverBrowser.servers count];

}

- (id)tableView:(NSTableView *)tableView
                objectValueForTableColumn:(NSTableColumn *)tableColumn
                row:(int)row
{
    NSLog(@"Starting updates for table");
    NSNetService* server = [serverBrowser.servers objectAtIndex:row];
    return [server name];

}

- (IBAction)tableViewSelected:(id)sender
{
    //row = [sender selectedRow];
    NSLog(@"the user just clicked on row ");
}

This is part of a chat program that I'm trying to expand. It was designed for the iOS and I'm working to get it to work on my laptop and chat with my iPad. I know that updateServerList is called correctly from my log statement. I also now that numberOfRowsInTableView: is called on startup but not anytime else. I would like to have my Table (the outlet crazyStuff) updated everytime updateServerList is called. How would I trouble shoot to see if it is or is not? I am not seeing the data show up in the table that "should" be there


回答1:


I take it then that at startup, when numberOfRowsInTableView is called, it returns 0? If not, is tableView:objectValueForTableColumn:row: ever called then?

My first guess would be the "crazyStuff" is, in fact, not connected to anything or connected to something other than the table view you intend. Might want to log the value of crazyStuff in updateServerList.




回答2:


Within updateServerList you should [crazyStuff noteNumberOfRowsChanged]. I thought reloadData causes the table to re-ask its dataSource for the numberOfRowsInTableView:, though...



来源:https://stackoverflow.com/questions/5137213/nstableview-not-updating-like-i-think-it-should

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!