を知らせるコード:
RootViewController.h
@interface RootViewController : UIViewController {
UIButton *btnCountry;
UIButton *btnState;
NSMutableArray *tempArray;
NSMutableArray *countryArray;
NSMutableArray *stateArray;
IBOutlet UITableView *tempTable;
}
@property (nonatomic,retain) UIButton *btnCountry;
@property (nonatomic,retain) UIButton *btnState;
@property (nonatomic,retain) NSMutableArray *countryArray;
@property (nonatomic,retain) NSMutableArray *stateArray;
@property (nonatomic,retain) NSMutableArray *tempArray;
@property (nonatomic,retain) UITableView *tempTable;
- (IBAction) showState:(id)sender;
- (IBAction) showCountry:(id)sender;
@最後
RootViewController.m
@implementation RootViewController
@synthesize btnState,btnCountry, stateArray,countryArray,tempArray;
@synthesize tempTable;
#pragma mark -
#pragma mark View lifecycle
- (void)viewDidLoad {
[super viewDidLoad];
tempTable.hidden = YES;
countryArray = [[NSMutableArray alloc]initWithObjects:@"India",@"Pakistan",@"USA",nil];
stateArray = [[NSMutableArray alloc]initWithObjects:@"Gujarat",@"Maharashtra", @"Karnataka",nil];
tempArray = [[NSMutableArray alloc]init];
}
- (IBAction) showCountry:(id)sender
{
btnCountry = (UIButton *)sender;
tempArray = countryArray;
[tempTable reloadData];
if([btnCountry isSelected])
{
tempTable.hidden = YES;
btnCountry.selected = NO;
}
else
{
tempTable.hidden = NO;
btnCountry.selected = YES;
}
}
- (IBAction) showState:(id)sender
{
btnState = (UIButton *)sender;
tempArray = stateArray;
[tempTable reloadData];
if([btnState isSelected])
{
tempTable.hidden = YES;
btnState.selected = NO;
}
else
{
tempTable.hidden = NO;
btnState.selected = YES;
}
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [tempArray count];
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.text = [tempArray objectAtIndex:indexPath.row];
return cell;
}
@end
ポップアップはお勧めしません。最善の方法は、ピッカービューを2つのセクションで使用することです.1つはすべての国を持ち、もう1つは州を持ちます。 – utsabiem