我从今天开始开始使用IOS,并开始在现有项目上做一些小的改动。通过界面生成器,我可以添加一个按钮。现在,当点击该按钮时,我想从不同的故事板打开另一个控制器。IOS - 点击按钮时打开另一个控制器
这是我homecell.m
#import "HomeTableViewCell.h"
#import "HostListingsViewController.h"
@implementation HomeTableViewCell
- (void)awakeFromNib {
// Initialization code
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
- (IBAction)sharetapped:(id)sender {
// here i want to be redirected to another controller
}
@end
这是我homecell.h
#import <UIKit/UIKit.h>
@interface HomeTableViewCell : UITableViewCell
@property (weak, nonatomic) IBOutlet UIImageView *imageViewHome;
@property (weak, nonatomic) IBOutlet UILabel *labelHeading;
@property (weak, nonatomic) IBOutlet UILabel *labelSubHeading;
- (IBAction)sharetapped:(id)sender;
@end
我在谷歌搜索,是无法理解。所以我在这里寻求你的帮助。我正在使用xcode8。
Th易于使用的解决方案是在UItabelViewCell的“cellForRowAtIndexPath”instread中将按钮目标添加到ViewController。你可以在这篇文章中找到解决方案http://stackoverflow.com/questions/15652133/how-to-set-action-for-uibutton-in-uitableviewcell –
@Sandeep库马尔你已经链接到的答案是有一个表格视图单元格中的按钮。操作在其单元格中没有按钮 – Gruntcakes
“我想从不同的故事板打开另一个控制器”这是正确的吗?您今天只能盯着iOS,但您的项目中已经有不止一个故事板。似乎有点过于进步第一天 – Gruntcakes