Perform a Segue Called by a UITableViewCell

故事扮演 提交于 2019-12-05 21:15:48

I think your problem is with this ViewController *viewController = [[ViewController alloc] init]; [viewController action]; You are initiating a new ViewController and not getting the current one the cell is in.

Maybe you can set a delegate on the cell so the cell has a reference to the viewController

The simple approach to create a button and call its handler programatically is

UIButton *button=[UIButton buttonWithType:UIButtonTypeRoundedRect];
[button setFrame:CGRectMake(100, 100, 80, 40)];
[button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchDown];
[self.view addSubview:button]; //self.view is the view on which you want to add button

and its handler should be defined like this in your implementation file:

-(void)buttonClick:(id)sender{
    NSLog(@"button clicked");
    // your code on click of button 
}

You can check iOS documentation.

Hope this will help you to find out your problem. :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!