0

これは、ProfilTableViewController.m のテーブル ビュー デリゲートの If ステートメントの抜粋です。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
 {
UITableViewCell *currentCell =(UITableViewCell *)[tableView cellForRowAtIndexPath:indexPath];
// Navigation logic may go here. Create and push another view controller.
if (currentCell.textLabel.text==@"phrase") {
    MainViewController *phraseViewController =[[MainViewController alloc] initWithNibName:@"mesPhrase" bundle:nil];
    [self.navigationController pushViewController:phraseViewController animated:YES];
}

ストーリーボードで、ProfilTVC のセルから MainViewController へのプッシュを作成し、TableViewController を「MainViewController」に変更しました。

アプリを実行すると、ProfilViewController のセルをクリックしても何も起こりません:/ wtf?

乾杯、ルイ

4

2 に答える 2

1

currentCell.textLabel.text==@"phrase"内容ではなく文字列のアドレスを比較します。isEqualToString:メソッドを見てください。

于 2012-05-30T17:23:28.020 に答える
0

次のように prepareFor セグエを使用するだけです。

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Make sure we're referring to the correct segue
if ([[segue identifier] isEqualToString:@"yourIdentifier"]) {


   DestinationController *destination = [segue destinationViewController];

    // get the selected index
    NSInteger selectedIndex = [[self.tableView indexPathForSelectedRow] row];
    //now you can add informations you want to send to the new controller
    //example:
    destination.selectedItem=[myArray objectAtIndex:selectedIndex];

 }

}

セグエ識別子を変更することを忘れないでください: 2 つのコントローラー間のワイヤーを選択し、右側の属性インスペクターで設定します。これは youIdentifier と等しくなければなりません。

于 2012-06-01T10:33:24.917 に答える