如何使用NSString addTarget将一个addTarget对象作为参数传递给另一个方法:
这是我的代码:
- (void)vision:(PBJVision *)vision capturedVideo:(NSDictionary *)videoDict error:(NSError *)error
{
_recording = NO;
if (error) {
NSLog(@"encounted an error in video capture (%@)", error);
return;
}
_currentVideo = videoDict;
NSString *videoPath = [_currentVideo objectForKey:PBJVisionVideoPathKey];
NSLog(@"string = %@",videoPath);
UIButton *ok = [UIButton buttonWithType:UIButtonTypeRoundedRect];
ok.frame = CGRectMake(95, 3, 50, 30);
[ok setTitle:@"OK" forState:UIControlStateNormal];
[ok addTarget:self action:@selector(okwindow:) forControlEvents:UIControlEventTouchUpInside];
[customview addSubview:ok];
}如何将字符串值作为addTarget的参数传递:
请给出任何建议和解决办法.
发布于 2013-09-09 21:28:51
您可能想要访问okwindow:方法中的videoPath字符串吗?它不是通过通过按钮传递状态来完成的。按钮用于收集触摸事件。
相反,通过添加一个属性来更改视图控制器的状态。
@property (nonatomic, strong) NSString *videoPath;当你拿到绳子时.
NSString *videoPath = [_currentVideo objectForKey:PBJVisionVideoPathKey];
NSLog(@"string = %@",videoPath);
self.videoPath = videoPath;当用户按下按钮时访问它..。
- (void)okwindow:(id)sender {
NSLog(@"I still have the string = %@",self.videoPath);
}https://stackoverflow.com/questions/18706998
复制相似问题