【问题标题】:navigational controller not passing data from tableview to viewcontroller导航控制器未将数据从 tableview 传递到 viewcontroller
【发布时间】:2013-03-21 07:39:57
【问题描述】:

Tableview 的代码:

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

    ViewControllerDisplayMsg *detail = [self.storyboard instantiateViewControllerWithIdentifier:@"viewController3"];


    cellvalue=[array objectAtIndex:indexPath.row];
    detail.DisplayMsgString = cellvalue;
    [self.navigationController pushViewController:detail animated:YES];

    }

viewController3 中的代码:

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.DisplayMsgLabel.text= self.DisplayMsgString;

}

上面的代码在viewcontroller3打开时没有传递数据,它是空白的。为什么数据没有传递。缺少什么代码?

请帮帮我。非常感谢您的帮助。

提前致谢。

【问题讨论】:

  • 你在ViewControllerDisplayMsg中创建了DisplayMsgString的属性并正确合成了吗?
  • 您好,先生。 @property (strong, nonatomic) IBOutlet UILabel *DisplayMsg; @property(strong,nonatomic)NSString *DisplayMsgString; 这是它在 .h 中的样子,我还没有合成为它在 ios6.1 xcode 4.6 中自动合成正确?
  • 不,没关系,您不必在 ios 6.1 中进行合成
  • 检查 IB 中的 UILabel 连接;代码对我来说看起来不错。
  • 你好,马特,我这样做了两次。

标签: ios uitableview ios5 ios6 uinavigationcontroller


【解决方案1】:

你用过

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

       }

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

       }

希望你打错了,如果不是这个,请分享你的结果

【讨论】:

  • 我进行了上述更改,但仍然是空白??我不知道为什么?
  • wat 是空白的吗?您是否将委托设置为您的 tableview 只需尝试在您的 didSelectRowAtIndexPath 中添加 NSLog
  • 抱歉回复晚了。另一个控制器中的标签应该设置在该行中选择的数组的值的文本值是空白的。我已经在 didSelectRowAtIndexPath 中添加了日志,它工作正常我有价值,但它没有转移到另一个控制器。
  • @property (strong, nonatomic) IBOutlet UILabel *DisplayMsg; @property(strong,nonatomic)NSString *DisplayMsgString; 在 .h 文件和 - (void)viewDidLoad { [super viewDidLoad]; self.DisplayMsg.text=self.DisplayMsgString; // self.DisplayMsg.text= _DisplayMsgString; } 在 .m 文件中
  • 尝试仅在 NSLog DisplayMsgString 中打印 viewDidLoad 中的值,并将标签 textcolor 设置为与背景颜色不同的颜色
【解决方案2】:

由于我从情节提要中获得了 segue,所以没有调用 didselect 方法 -

(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // test segue.identifier if needed
    ViewControllerDisplayMsg *viewController = segue.destinationViewController;
    NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
    // set properties of viewController based on selection indexPath


    cellvalue=[array objectAtIndex:indexPath.row];

    NSLog(@"str :  %@",cellvalue);
    viewController.DisplayMsgtext = cellvalue;

}

这工作得很好。我必须检查它是否是正确的实施方式,否则它现在工作正常。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-01-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-03-19
  • 2021-07-21
相关资源
最近更新 更多