0

以下に示すように、プロジェクトの最初のシーンは動的セル ビューです。コード内で参照できるように、これに識別子を付けました。

動的セル

期待どおりに表示されるコード内から、グループ化された 2 番目のセクションを作成しました。ユーザーが最初のセルをクリックすると、ある特定のシーンに移動しますが、2 番目のセルも同じシーンに移動します。

別のシーンへのセグエを作成できるように、2 番目のセルに別の識別子を与えるにはどうすればよいですか? 2 番目のセルはストーリーボードに表示されないため、そのようにすることはできません。

現時点でこのシーン用に持っているコードは次のとおりです。

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController
@synthesize testLocation;

- (void)viewDidLoad
{

    testLocation = @"Washington, Dulles";
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}


#pragma mark - Table View Methods

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;              // Default is 1 if not implemented
{
    return 2;
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section;    // fixed font style. use custom view (UILabel) if you want something different

{
    if (section == 0) {
        return @"Choose Test Location:";
    }
    else {
        return @"Choose Test Type:";
    }
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;

{
    if (section == 0) {
        return 1;
    }
    else {
        return 1;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;

{


    UITableViewCell *serverLocCell = [tableView dequeueReusableCellWithIdentifier:@"serverLocation"];

    switch (indexPath.section) {
        case 0:
            serverLocCell.textLabel.text = testLocation;
            serverLocCell.detailTextLabel.text = @"Change";
            break;
        case 1:
            serverLocCell.textLabel.text = @"Speed Test";
            serverLocCell.detailTextLabel.text = @"Change";
            break;
        default:
            break;
    }

    return serverLocCell;

}

@end
4

1 に答える 1

1

ストーリーボード エディターで、使用する 2 つのセグエを作成しますが、テーブル ビューからではなく、1 つのコントローラーから次のコントローラーにセグエします。コントローラーレベルで実行してください。各セグエに特定の異なる名前を付けます。

didSelectRowAtIndexPathユーザーがテーブル内のセルを選択したときにわかるように実装します。インデックス パスのセクション (または行) に応じて、プログラムでセグエを起動します。

于 2013-01-16T21:36:09.827 に答える