-1

ViewController1 に UITableView があります。選択すると、ViewController2 が読み込まれ、選択されたそれぞれの行の名前を持つ変数 (「passedData」として宣言されている)が保持されます。コードの実行可能性をテストする際に、ViewController2 のラベルに「passedData」を次のように割り当てました。

label.text = "passedData";

それはうまく機能します。ViewController1 のテーブルビューのリストには、サマリー、レポート、詳細などの一時的な命名規則で配列からロードされた行があります。

したがって、「Summary」を選択すると、ViewController2 がロードされ、それが SummaryViewController に関連する別のサブビューをロードします。ViewController2にサブロードするView Controllerを認識させようとして、私はこれを-(void) viewDidLoad:

NSString *viewtoload = passedData;
    if (viewtoload == "Summary") {
        //Load summaryViewController
    }
    elseif (viewtoload == "Report") {
        //Load reportViewController
    }
    elseif (viewtoload == "Detail") {
        //Load detailViewController
    }

私はこのエラーを受け取りました:

1. Implicit conversion of a non-objective-C pointer type 'char *' to 'NSString *' is disallowed with ARC.
2. Result of comparison against a string literal is unspecified (use strncmp instead)
3. Comparison of distinct pointer types ('NSString *' and 'char *')

私の質問は次のとおりです。

1)これは正しいアプローチですか、それともより良い方法がありますか?

2) 上記のエラーを解決するにはどうすればよいですか?

3) 別のサブビューをロードする構文は?

よろしくお願いします。

4

2 に答える 2

1

タップされたセルに応じて異なるViewControllerをロードする場合は、

//handle selections of cell in specified row and section of table view
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    //switch row
    switch(indexPath.row)
    {

        case:0
        {
            //Detail row
            Detail01 *viewController = [[Detail01 alloc] init];
            viewController.somePassedInData = theDataToPass;
            [self presentViewController:viewController animated:YES completion:nil];
            break;
        }
        case:1
        {
            //Report row
            Report01 *viewController = [[Report01 alloc] init];
            viewController.somePassedInData = theDataToPass;
            [self presentViewController:viewController animated:YES completion:nil];
            break;
        }
        case:2
        {
            //Summary row
            //Alloc and init VC here
            Summary01 *viewController = [[Summary01 alloc] init];
            viewController.somePassedInData = theDataToPass;
            [self presentViewController:viewController animated:YES completion:nil];
            break;
        }
        default:
        {
            break;
        }
    }

    //deselect table cell
    [_tableView deselectRowAtIndexPath:indexPath animated:YES];
}    

その後、ナビゲーションコントローラにプッシュする前に、VCに任意のプロパティを設定できます

于 2013-03-22T16:24:17.927 に答える
0

@""代わりに正しいobjective-c文字列リテラルを使用してください""

于 2013-03-22T09:21:25.667 に答える