Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 如何将字符串传递给目标C中的选择器(在UITableView单元格内)_Objective C_Iphone - Fatal编程技术网

Objective c 如何将字符串传递给目标C中的选择器(在UITableView单元格内)

Objective c 如何将字符串传递给目标C中的选择器(在UITableView单元格内),objective-c,iphone,Objective C,Iphone,我实现了一个UITableView,在每个单元格中我有两个按钮。当按下其中一个按钮时,我需要将从相关单元格中提取的字符串传递给另一个方法[ShowMeThePassedString]。为了简化下面的代码,我尝试检索一个全局变量 这是我的代码,但我得到以下错误:“无法识别的选择器发送到实例”。有什么建议吗?谢谢 //in .h - (NSString *) ShowMeThePassedString:(NSString*) TESTvalue; //in .m NSString *TEST_st

我实现了一个UITableView,在每个单元格中我有两个按钮。当按下其中一个按钮时,我需要将从相关单元格中提取的字符串传递给另一个方法[ShowMeThePassedString]。为了简化下面的代码,我尝试检索一个全局变量

这是我的代码,但我得到以下错误:“无法识别的选择器发送到实例”。有什么建议吗?谢谢

//in .h
- (NSString *) ShowMeThePassedString:(NSString*) TESTvalue;

//in .m
NSString *TEST_string = @"Hi there!";

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

     //Add a button
     button = [UIButton buttonWithType:UIButtonTypeRoundedRect]
     [button setTitle:@“Show me the string“ forState:UIControlStateNormal];
     button.frame = CGRectMake(260, cell.center.y - 15, 53, 30);
     [button addTarget:self action:@selector(ShowMeThePassedString:TEST_string:) forControlEvents:UIControlEventTouchUpInside];
     [cell addSubview:button];
}

- (NSString *) ShowMeThePassedString:(NSString*) TESTvalue
{
    NSLog(@"TEST result %@", TESTvalue);
    return TESTvalue;
}
换成这个

[button addTarget:self action:@selector(ShowMeThePassedString:) forControlEvents:UIControlEventTouchUpInside];


- (NSString *) ShowMeThePassedString:(id)sender
{    
    UIButton *button = (UIButton*)sender;
    NSLog(@"TEST result %@", button.titleLabel);
    return button.titleLabel;
}

谢谢,但我不认为这对我的目的有用,那就是访问存储在特定单元格中的字符串。我不应该使用全局变量简化这个问题!好的,等一下,我会给你一个不同的答案