0

3 つの異なるテーブルと、ラベルを含む単一の UiView があるアプリを開発しています。その選択したテーブルビューセル名の表示名をラベルに設定したい。

    (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
    AppDelegate * appdelegate=(AppDelegate *)[[UIApplication sharedApplication]delegate];

    if(appdelegate.btn1)
    {
        appdelegate.selectId=indexPath.row;
        NSLog(@"select Id %d",appdelegate.selectId);    
    }
    else if(appdelegate.btn2)
    {
        appdelegate.selectId=indexPath.row;
        NSLog(@"select Id %d",appdelegate.selectId);
    }
    else if(appdelegate.btn3)
    {
        appdelegate.selectId=indexPath.row;
        NSLog(@"select Id %d",appdelegate.selectId);
    }

    NSString * str=[appdelegate.name objectAtIndex:indexPath.row];
    NSString * str1=[appdelegate.iname objectAtIndex:indexPath.row];
    NSString * str2=[appdelegate.bname objectAtIndex:indexPath.row];

    DetailViewController * dvc=[[DetailViewController alloc]initWithTrick:str andOtherString:str1 andOtherString:str2];

    [self.navigationController pushViewController:dvc animated:YES];

}

そして、そのセル名にinitメソッドにアクセスします。

 -(id)initWithTrick:(NSString *)name_ andOtherString:(NSString *)name2_ andOtherString:(NSString *)name3_;
{
       if (self)
       {

           self.trickname=name_;
           self.trickname2=name2_;
           self.trickname3=name3_;

    }
    return self;


  }

ここで、trickname、trickname2、trickname3 は NSString です。

このコードを試しましたが、うまくいきません。

これを手伝ってください。

4

4 に答える 4

1
 -(id)initWithTrick:(NSString *)name_ andOtherString:(NSString *)name2_ andOtherString:(NSString *)name3_;
{ 
  self =[super init]; 
   if (self)
   {

       self.trickname=name_;
       self.trickname2=name2_;
       self.trickname3=name3_;

}
return self;
}

これを試してみてください。あなたの自己オブジェクトは初期化されていないので、値は文字列に設定されていません。

于 2013-05-04T07:26:37.377 に答える
0

私は今私の問題を解決します。

テーブルビューコントローラーでその文字列を宣言します

{
    NSString * str;
    NSString * str1;
    NSString * str2;
}
@property(strong,nonatomic)NSString * str;
@property(strong,nonatomic)NSString * str1;
@property(strong,nonatomic)NSString * str2;

テーブル ビュー コントローラーの .m で合成します。

 @synthesize str,str1,str2;

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


        AppDelegate * appdelegate=(AppDelegate *)[[UIApplication sharedApplication]delegate];

        if(appdelegate.btn1)
        {
            appdelegate.selectId=indexPath.row;
            NSLog(@"select Id %d",appdelegate.selectId);

            str=[appdelegate.name objectAtIndex:indexPath.row];

         }

        else if(appdelegate.btn2)
        {
            appdelegate.selectId=indexPath.row;

            NSLog(@"select Id %d",appdelegate.selectId);


            str1=[appdelegate.iname objectAtIndex:indexPath.row];

        }

        else if(appdelegate.btn3)
        {

            appdelegate.selectId=indexPath.row;

            NSLog(@"select Id %d",appdelegate.selectId);

                str2=[appdelegate.bname objectAtIndex:indexPath.row];

        }

    DetailViewController * dvc=[[DetailViewController alloc]initWithTrick:str andOtherString:str1 andOtherString:str2];

        dvc.trickname=str;
        dvc.trickname2=str1;
        dvc.trickname3=str2;

        NSLog(@"%@",str);

        appdelegate.counter=0;

    [self.navigationController pushViewController:dvc animated:YES];

  }

次に、Detailview Controller に移動し、Detailview Controller の init() メソッドを介してこの 3 つの文字列にアクセスします。

最初にDetailVewController.hでその init メソッドを定義します

-(id)initWithTrick:(NSString *)name_ andOtherString:(NSString *)name2_ andOtherString:(NSString *)name3_;

@property(nonatomic,retain)NSString * trickname;

@property(nonatomic,retain)NSString *  trickname2;

@property(nonatomic,retain)NSString *  trickname3;

DetailViewController.m

@synthesize trickname;
@synthesize trickname2;
@synthesize trickname3;

-(id)initWithTrick:(NSString *)name_ andOtherString:(NSString *)name2_ andOtherString:(NSString *)name3_;

{

    self=[super init];
       if (self)
       {

           self.trickname=name_;
           self.trickname2=name2_;
           self.trickname3=name3_;

    }
    return self;
}
于 2013-05-06T05:32:26.220 に答える
0

代わりにこれを行うことができます:

DetailViewController.hクラスで 3 つのプロパティ文字列を次のように作成します。

@property (strong, nonatomic) NSString *name1;
@property (strong, nonatomic) NSString *name2;
@property (strong, nonatomic) NSString *name3;

そして、DetailViewController.mクラスでこれらを次のように合成します。

@synthesize name1,name2,name3;

そして、テーブルビューデリゲートでこれらにアクセスします

    DetailViewController * dvc=[[DetailViewController alloc]initWithTrick:str andOtherString:str1 andOtherString:str2];
dvc.name1= str;
dvc.name2= str1;
dvc.name3= str2;

    [self.navigationController pushViewController:dvc animated:YES];

次に、init メソッドでそれらにアクセスします。

お役に立てば幸いです。

于 2013-05-04T05:50:40.917 に答える