我正在尝试将此indexPath.row
移至视图控制器pageView
[cell.nav addTarget:self action:@selector(naviguate:) forControlEvents:UIControlEventTouchUpInside];
cell.nav.tag=indexPath.row;
在表格单元格内有一个按钮nav
pageView
-(void)naviguate:(id)sender {
[UIView animateWithDuration:0.5
delay:0
options: UIViewAnimationOptionCurveEaseOut
animations:^{
[_tableView setFrame:CGRectMake(0, 569, _tableView.frame.size.width, _tableView.frame.size.height)];
}
completion:^(BOOL finished){
[self performSegueWithIdentifier:@"link" sender:self];
}];
}
其中link
是隐含标识符
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
UIButton *theButton=(UIButton *)sender;
if([segue.identifier isEqualToString:@"link"])
{
NSLog(names[theButton.tag]);
controller.name.text = names[theButton.tag];
}
}
其中name
是pageView
但我收到错误:
-[ImagesTableViewController tag]: unrecognized selector sent to instance
没有记录怎么回事?我做错了什么?
答案 0 :(得分:1)
不要从imageViewController
设置控件(标签)属性,而是要将NSString
传递给pageView的新实例。
执行segue后,在viewDidLoad
将属性添加到pageView.h
@property (strong, nonatomic) IBOutlet NSString *blogName;
更改segue代码
controller.name.text = names[theButton.tag];
到
controller.blogName = names[tag];
页面viewDidLoad
中的
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.name.text = _blogName;
}
答案 1 :(得分:0)
进一步了解@bobnoble的解释:
在naviguate
方法中,您可以致电
[self performSegueWithIdentifier:@"link" sender:self];
请注意,你通过" self"作为发件人。这意味着在prepareForSegue中,sender参数将包含当前视图控制器。
如果您的naviguate
方法是IBAction,正如它有发件人参数所示,为什么不改变它:
-(IBAction) naviguate:(id)sender
{
[UIView animateWithDuration:0.5
delay:0
options: UIViewAnimationOptionCurveEaseOut
animations:^
{
[_tableView setFrame:CGRectMake(0, 569, _tableView.frame.size.width,
_tableView.frame.size.height)];
}
completion:^(BOOL finished)
{
[self performSegueWithIdentifier:@"link" sender: sender]; //Changed to pass sender
}
];
}
这样就可以将发送方从您的操作方法传递给seque。
我仍然会更改您的prepareForSegue方法,以确保发件人响应"标记"在尝试从中获取标记值之前的选择器:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
UIButton *theButton=(UIButton *)sender;
if([segue.identifier isEqualToString:@"link"])
{
int tag = -1
if (![theButton respondsToSelector: @selector(tag)])
NSLog(@"Sender does not respond to 'tag'!");
else
{
int tag = theButton.tag;
NSLog(names[tag]);
controller.name.text = names[theButton.tag];
}
}
}