您可以使用一个 UITableView 来显示所有数据。您可以使用 UIButtons 而不是使用 UISegmentedControl。在 UIButton 的 IBAction 中,您可以更改要显示的特定数据的 dataArray。喜欢
self.dataArray = array1;
[self.tableview reloadData];
并使用此 dataArray 在您的 UITableView 方法中显示数据。
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return dataArray.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
.....
}
或者
您可以使用我在我的一个应用程序中使用的不同方法。
#pragma mark - UITableView Delegate and DataSource
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
if (btnFavourites.selected) {
return arrFavourites.count;
}else if (btnHistory.selected){
return arrHistories.count;
}else if (btnHome.selected){
return arrAddresses.count;
}
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *cellIdentifier = @"MyCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
// Configure the cell...
if (btnHome.selected) {
Home *home = [arrAddresses objectAtIndex:indexPath.row];
cell.textLabel.text = home.address;//[address valueForKey:@"address"];
}else if (btnFavourites.selected){
Favourites *favourite = [arrFavourites objectAtIndex:indexPath.row];
cell.textLabel.text = favourite.location;//[favourite valueForKey:@"address"];
}else if (btnHistory.selected){
History *history = [arrHistories objectAtIndex:indexPath.row];
cell.textLabel.text = history.location;// [history valueForKey:@"address"];
}
return cell;
}
您可以根据您的要求进行定制。希望这可以帮助。谢谢。:)