ios - 将多个值传递给 nextview Controller

标签 ios objective-c

我正在开发一个应用程序,其中有三个不同的表格和一个包含标签的 UiView。我想显示所选表格 View 单元格名称的名称,将其设置为标签。

    (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。

我已经尝试过这段代码,但对我不起作用。

请帮我解决这个问题。

最佳答案

 -(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;
}

试试这个可能会对你有帮助。您的 self 对象未初始化,因此未在字符串中设置值。

关于ios - 将多个值传递给 nextview Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16370938/

相关文章:

ios - iPhone 启动画面后 RoboVM 崩溃

objective-c - 如何在Object-C中实现like JAVA ‘Protect’函数?

ios - map View 自动缩放当前位置自动

ios - 如何获取将要呈现的 HTML 字符串的高度?

ios - 如何使用 MPMusicPlayerController 从特定索引播放 MPMediaItemCollection?

ios - 为什么当我在 .m 文件中设置 ^block 变量时,我收到一条错误消息,提示 Thread_1 EXC_BAD_ACCESS

ios - 如何实现 "drag right to dismiss"导航堆栈中的 View Controller ?

ios - swift 2.1 : CAGradientLayer color location & distribution

objective-c - 无法通过我的应用程序发送电子邮件

ios - 使用 MDCTextInputControllerUnderline iOS Swift 更改 MDCTextField 中的占位符对齐方式