我想做两段,像这样
出发段将在 tableView 中显示出发航班,而返回段将显示返回航班。有人可以解释一下我应该怎么做吗?我应该制作 2 个 tableView 还是只制作一个?谢谢
您可以使用 One UITableView 来实现此目的,并在 segmentcontrolindexchange 方法上重新加载表数据。查看代码
- (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;
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)