[英]How can I reload data in tableview in view controller in iphone
I am new to iphone development. 我是iPhone开发的新手。 I have created 5 buttons in the view.
我在视图中创建了5个按钮。 On clicking the buttons it navigates to the corresponding views.
单击按钮后,它将导航到相应的视图。 On clicking the "News" button it navigates and displayed the parsing details in the table view.(This table view, I have created View controller and added table view using Interface Builder and I have set all the properties.) and I go to another button and comes back to the "News" button, every time parsing will happened.How to avoid the multiple parsing when I come back to the button.
单击“新闻”按钮时,它将导航并在表视图中显示解析详细信息。(此表视图已创建View控制器,并使用Interface Builder创建了表视图,并设置了所有属性。),然后转到另一个按钮,然后返回到“新闻”按钮,每次都会进行解析。当我回到该按钮时,如何避免多次解析。
I have tried this one and my code is, 我已经尝试过了,我的代码是,
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
static int i;
if(i == 0)
{
NSString * path = @"http://www.AAAAAAAAAAAAAA.com";
[self parseXMLFileAtURL:path];
i++;
}
[self.newsTable reloadData];
}
Now the parsing is happened only one time but the datas are not displayed. 现在解析仅发生一次,但数据不会显示。
My problem is the tableview does not reload. 我的问题是tableview无法重新加载。 newsTable is the instance of the Tableview.
newsTable是Tableview的实例。
How can I achieve this? 我该如何实现?
Please help me out. 请帮帮我。
[self.newsTable reloadData];
put this line on click of news button. 将此行放在“新闻”按钮上。
it reloads the table view whenever you click. 只要单击,它就会重新加载表格视图。 since view did load calls only one time thats why no reload of table view take place.
因为视图只加载一次调用,所以为什么没有重新加载表视图。
I suppose, that you are using NSXMLParser. 我想,您正在使用NSXMLParser。
The parser has a few delegate methods that you'll want to implement: 解析器有一些您要实现的委托方法:
parser:didStartElement:namespaceURI:qualifiedName:attributes:
parser:didEndElement:namespaceURI:qualifiedName:
parserDidEndDocument:
So, you just need to put reloadData invocation into parserDidEndDocument:
因此,您只需要将reloadData调用放入
parserDidEndDocument:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.