我的 tableview 控制器上有一个段。
segmentIndex=0 -> tableView 正在加载 -> 点击。导航到另一个 tableViewController。segmentIndex=1 -> 加载 tableView -> 点击。导航到另一个 tableViewController。
切换 tableviews 很好。问题是导航回来后我需要记住以前的索引值。如何实施?我当前的代码:
- viewWillAppear
self.segment=[[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"Nominals",@"Coinage",nil]];
[self.segment setFrame:CGRectMake(80, 0, 200, 30)];
[self.segment setSegmentedControlStyle:UISegmentedControlStyleBar];
//self.segment.selectedSegmentIndex=0;
[self.segment addTarget:self action:@selector(segmentValueChaged:) forControlEvents:UIControlEventValueChanged];
[[self navigationItem] setTitleView:self.segment];
-(IBAction)segmentValueChaged:(id)sender
{
switch (self.segment.selectedSegmentIndex)
{
case 0:
{
DBAccess *access=[[DBAccess alloc]init];
self.items=[access returnNominals:self.subCountryID nk:fromPeriod];
[access closeDataBase];
self.tableView.hidden=NO;
[self.tableView reloadData];
self.segmentIndex=0;
break;
}
case 1:
{
DBAccess *access=[[DBAccess alloc]init];
self.coinageArr=[access returnCoinage:fromPeriod period:subCountryID];
self.tableView.hidden=NO;
[self.tableView reloadData];
self.segmentIndex=1;
break;
}
}
}
提前谢谢你们。
编辑:
self.segment=[[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"Nominals",@"Coinage",nil]];
[self.segment setFrame:CGRectMake(80, 0, 200, 30)];
[self.segment setSegmentedControlStyle:UISegmentedControlStyleBar];
if(!self.segmentIndex)
{
self.segment.selectedSegmentIndex=-1;
}
else
{
self.segment.selectedSegmentIndex=self.segmentIndex;
}
//self.segment.selectedSegmentIndex=self.segmentIndex;
[self.segment addTarget:self action:@selector(segmentValueChaged:) forControlEvents:UIControlEventValueChanged];
[[self navigationItem] setTitleView:self.segment];
-(void)viewWillDisappear:(BOOL)animated
{
switch (self.segment.selectedSegmentIndex)
{
case 0:
{
self.segmentIndex=0;
break;
}
case 1:
{
self.segmentIndex=1;
break;
}
}
}