如何在分段控件更改后重新加载UITableView? [英] How to reload a UITableView after a segmented control changed?
本文介绍了如何在分段控件更改后重新加载UITableView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图用分段控件(在tableview之上)控制tableview的上下文。在更改段我想在表tableView中使用不同的单元格重新加载数据(我有两种类型的单元格,每种类型有两个数据数组)。如何使用不同的单元格清除和重新加载数据?
I am trying to control context of tableview with segmented control(which is above tableview). On change segment I want to reload data in my table tableView with different cells ( I have two types of cells and two data arrays for every type). How to clear and reload data with different cell ?
推荐答案
我只是为@jaydee3提供了几行代码提到。
I'm just providing a few lines of code to what @jaydee3 has mentioned.
- (IBAction)segmentControlValueChanged:(UISegmentedControl *)sender
{
//Do something
[self.tableView reloadData];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.segmentControl.selectedSegmentIndex?[self.dataArray2 count]:[self.dataArray1 count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(self.segmentControl.selectedSegmentIndex){
// Create Type cell for selected Index 1
}
else{
// Create Type cell for selected Index 0
}
}
这篇关于如何在分段控件更改后重新加载UITableView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文