use*_*567 7 iphone objective-c
我想制作两个片段,就像这样

deparature段将在tableView中显示deverature fly,然后回归flyback.请问我能解释一下我该怎么做?我应该制作2个tableView还是只制作一个?谢谢
iPr*_*mer 17
您可以使用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;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15562 次 |
| 最近记录: |