0
我想要做的是使用pickerview中的選擇來填充另一個視圖控制器上的tableview。用戶在選取器視圖上進行選擇,然後點擊按鈕以轉到下一個視圖控制器,該視圖控制器根據pickerview選項在tableview中顯示不同的數組。使用pickerview選擇來填充tableview時出現問題
我對編碼頗爲陌生,所以我不知道我的代碼是否遠遠接近正確。反正繼承人什麼我已經試過:
@interface HomeViewController()
@end
@implementation HomeViewController{
}
@synthesize tableview;
- (void)viewDidLoad
{
[super viewDidLoad];
_pickerarray = [[NSArray alloc] initWithObjects:@"1",@"2",@"3", nil];
_array1 = [[NSArray alloc] initWithObjects:@"1980",@"1981",@"1982", nil];
_array2 = [[NSArray alloc] initWithObjects:@"1983",@"1984",@"1985", nil];
_array3 = [[NSArray alloc] initWithObjects:@"1986",@"1987",@"1988", nil];
}
- (void)didReceiveMemoryWarning
{
[self setPicker:nil];
[super didReceiveMemoryWarning];
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
return _pickerarray.count;
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
return [_pickerarray objectAtIndex:row];
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
switch (row) {
case 0:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [_array1 count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"cell";
UITableViewCell *cell = [tableview dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
cell.textLabel.text = [_array1 objectAtIndex:indexPath.row];
return cell;
}
break;
case 1:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [_array2 count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"cell";
UITableViewCell *cell = [tableview dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
cell.textLabel.text = [_array2 objectAtIndex:indexPath.row];
return cell;
}
break;
case 2:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [_array3 count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"cell";
UITableViewCell *cell = [tableview dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
cell.textLabel.text = [_array3 objectAtIndex:indexPath.row];
return cell;
}
default:
break;
}
}
@end
上的代碼行
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
我得到一個語義問題,說明
我真的很感激,「未聲明的標識符‘的tableview’的使用」任何反饋,正如我所說我很新,我甚至不知道我是否以正確的方式開展這項工作,所以如果有人能夠把我引向正確的方向,那將是非常棒的!