2011-09-16 5 views
0
I have two class `first` class and `second` class 

I have created 3 section on `tableview` cell for display different value 
If I select on section 0 and `indexpath.row` 0 then it push me on `second` class where I have all name list in `tableview` if i select any name then that name should display on first class on section 0 after it happen then i can sent this display value to server please help me on this 
what i have to write on second class this method: 

私はこのエラーを取得 - [空港isEqualToStringは:]:認識されていないセレクタはインスタンスに送信0x4e54760 2011-09-16 16:44:37.693 RegexKitLiteDemo [36975:207] *によりキャッチされない例外 'NSInvalidArgumentException'、理由にアプリを終了: ' - [isEqualToString空港:]:認識されないセレクターインスタンス0x4e54760に送ら'は、iPhoneの最初のクラスindexpath.rowに第二のクラスから選択された値を送信する方法

this is my Tfirst.m file 



- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath 
{ 
    NSLog(@"accessory selected"); 


    if ([indexPath section] == 0) 
    { 
     // load the appropriate view for the accessory selected 
     if ([indexPath row] == 0) 
     { 
      [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(nameControllerDidSelect:) name:NameControllerDidSelectNotification object:viewtwo]; 

      viewtwo=[[Originstart alloc]initWithNibName:@"Originstart" bundle:nil]; 
      [self.navigationController pushViewController:viewtwo animated:YES]; 
      [viewtwo release]; 
} 
     else{ 
      NSLog(@"accessory right"); 
      } 

     //[self.navigationController pushViewController:self.approve animated:YES]; 


    } 
} 






my Origin.m file 

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

    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease]; 
    } 

    a=(airport*)[app.lstAirports objectAtIndex:indexPath.row]; 
    NSLog(@"str:%@",a); 
    cell.textLabel.text =a.Name; 
cell.detailTextLabel.text=a.Code; 
    // Configure the cell... 

    return cell; 
} 




#pragma mark - 
#pragma mark Table view delegate 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 



    a.Name = [app.lstAirports objectAtIndex:indexPath.row]; 

    // Send notification of new selection 
    NSDictionary *userDict = [NSDictionary dictionaryWithObject:a.Name forKey:@"Name"]; 
    NSLog(@"str:%@",userDict); 
    [[NSNotificationCenter defaultCenter] postNotificationName:NameControllerDidSelectNotification object:self userInfo:userDict]; 
       } 
+0

構文を使用して投稿を書くことはできますか? – beryllium

答えて

0

私はあなたを渡すために、デリゲートを使用する方法を示しsmall example projectを書きましたその情報は第2のビューコントローラから戻される。

これは大したことですが、あなたはそのアイデアを得るべきです。

+0

アビザンは助けてくれた友人に感謝しますが、私はそれをやってしまったのですが混乱しています。私のデータはそれを渡していないapp.lstAirportsのNSCFStTringベアはアレイであり、私はこの配列名とコードから2つの値を得たいので、このような値をtakeen =(空港*)[app.lstAirports objectAtIndex:indexPath.row]; NSLog(@ "str:%@"、a); cell.textLabel.text = a.Name; cell.detailTextLabel.text = a.Code; app.lstAirportsまたは文字列aを渡す値を選択しました。私が値を選択した値を配列に渡すときの名前は、debegerで表示されますが、値は渡されません。 – Rocky

+0

@Rocky - 私は助けたいと思いますが、あなたが何を求めているのか理解できません。ごめんなさい。 – Abizern

+0

友人に感謝私の問題は私の間違いだ解決する私はパスの文字列の値だったなぜ私はエラーを取得するurデモアプリケーション – Rocky

1

は、のように思えますプロトコルと代理人の場合..より良いチュートリアルを読んでください....例えば.. http://iosdevelopertips.com/objective-c/the-basics-of-protocols-and-delegates.htmlv

+0

ya friend私は知っていますが、使い方を教えてください。ステップバイステップで私はこの文書を読むが、適切ではない – Rocky

+0

それはチュートリアルで最もよく理解できる長いプロセスです... –

1

これを達成する方法の1つは通知によるものです。上位レベルのテーブルビューコントローラを登録してNameControllerDidSelectNotification(またはそれに類するもの)を受け取るようにします。第二レベルのテーブルビューコントローラでは、呼び出されたときtableView:didSelectRowAtIndexPath:、辞書オブジェクトに新しい選択を追加し、通知にそれを投稿:オブザーバーとして

#define NameControllerDidSelectNotification @"NameControllerDidSelectNotification" 


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    //... 

    // Store the selection 
    self.name = [self.namesArray objectAtIndex:indexPath.row]; 

    // Send notification of new selection 
    NSDictionary *userDict = [NSDictionary dictionaryWithObject:self.name forKey:@"Name"]; 
    [[NSNotificationCenter defaultCenter] postNotificationName:NameControllerDidSelectNotification object:self userInfo:userDict]; 
} 

とバックあなたのトップレベルのビューコントローラでは、最初のレジスタ通知の(あなたがセカンドレベルコントローラーを押したときに、これを行うには良い点である)、およびnameControllerDidSelect:を発射するよう指示:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(nameControllerDidSelect:) name:NameControllerDidSelectNotification object:nextController]; 

    // ... 
    // [self.navigationController pushViewController:nextController animated:YES]; 
    // ... 
} 

- (void)nameControllerDidSelect:(NSNotification *)notification 
{ 
    NSDictionary *userDict = [notification userInfo]; 
    self.selectedName = [userDict objectForKey:@"Name"]; 

    // Only do this here if your controller automatically pushes back to top-level on selecting a name, else put it in -viewWillAppear 
    [[NSNotificationCenter defaultCenter] removeObserver:self]; 
} 
+0

問題があれば私はあなたに言うでしょう – Rocky

+0

self.selectedNameこれは私がこの行にエラーを取得しようとする – Rocky

+0

@Rocky:私はあなたのコントローラオブジェクトに 'selectedName'という名前のプロパティを作成して、新しく選択した名前を保存すると仮定しています。あなたはあなたが好きなものを呼び出すことができます、あなたのインターフェイスでそれを宣言することを確認してください。 – Stuart

関連する問題