如何在UITableView中使用UISegmentedControl [英] How to use UISegmentedControl with UITableView
本文介绍了如何在UITableView中使用UISegmentedControl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想制作2段,类似这样的
I'd like to to make 2 segments, something like this
deparature段将在tableView中显示deverature fly,并在回归中显示回归段。请告诉我,我该怎么做?我应该制作2个tableView还是只制作一个?谢谢
the deparature segment will display the deparature fly in a tableView and the comeback segment the comeback fly . Can somene please explain me how should I do this? Should I make 2 tableView or just one? thank you
推荐答案
您可以使用One UITableView来实现此目的,并在segmentcontrolindexchange方法上重新加载表数据。查看代码
You Can use One UITableView for this purpose and reload table data on segmentcontrolindexchange method.Look At code
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return 1;
}
-(NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section
{ if(segment.selectedSegmentIndex==0)
{
return [List count];
}
else
if (segment.selectedSegmentIndex==1) {
return[List1 count];
}
return 0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
lbl1 = [[UILabel alloc]initWithFrame:CGRectMake(200, 10, 100, 20) ];
// Configure the cell...
lbl =[[UILabel alloc]initWithFrame:CGRectMake(100, 10, 100, 20) ];
if(segment.selectedSegmentIndex==0)
{
cell.textLabel.text=[List objectAtIndex:indexPath.row];
lbl.text = [List3 objectAtIndex:indexPath.row];
[cell.contentView addSubview:lbl];
lbl1.text = [List objectAtIndex:indexPath.row];
[cell.contentView addSubview:lbl1];
}
else if(segment.selectedSegmentIndex==1) {
cell.textLabel.text=[List1 objectAtIndex:indexPath.row];
lbl.text = [List objectAtIndex:indexPath.row];
[cell.contentView addSubview:lbl];
}
return cell;
}
-(IBAction) segmentedControlIndexChanged
{
switch (self.segment.selectedSegmentIndex) {
case 0:
i=0;
[table reloadData];
break;
case 1:
i=1;
[table reloadData];
default:
break;
}
}
这篇关于如何在UITableView中使用UISegmentedControl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文