iphone – 如何在UITableView中使用UISegmentedControl

我想制作两个片段,就像这样

deparature片段将在tableView中显示deverature fly,并在复出中显示复原段.请告诉我,我该怎么做?我应该制作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;
    }



}
翻译自:https://stackoverflow.com/questions/6110292/how-to-use-uisegmentedcontrol-with-uitableview

转载注明原文:iphone – 如何在UITableView中使用UISegmentedControl