0

私がやろうとしているのは、ピッカービューからの選択を使用して、別のビュー コントローラーにテーブルビューを設定することです。ユーザーはピッカー ビューで選択を行い、ボタンをタップして次のビュー コントローラーに移動します。ビュー コントローラーは、ピッカー ビューの選択に応じてテーブルビューにさまざまな配列を表示します。

私はコーディングにまったく慣れていないので、自分のコードが少しでも正しいかどうかはわかりません。とにかく、私が試したことは次のとおりです。

@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」の使用」という意味の問題が発生します

私はまったく新しいものであり、これを正しい方法で行っているかどうかさえわからないと言ったので、フィードバックをいただければ幸いです。誰かが私を正しい方向に導くことができれば、それは素晴らしいことです!

4

1 に答える 1

0

初心者として、無料の Sensible TableView フレームワークなどのテーブルビュー フレームワークを使用することをお勧めします。これらのフレームワークを使用すると、このようなタスクをほとんど箱から出して簡単に実現できます。プロジェクトの時間を大幅に節約できます。

于 2013-07-15T19:46:25.527 に答える