我從今天開始開始使用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