以编程方式创建segue从xib文件到storyboard中的viewcontroller

时间:2016-04-27 16:20:22

标签: ios objective-c segue xib

我使用的文件在objective-c

中有一个xib文件

我的故事板上有快速的课程

我需要从该xib文件创建segue到我的故事板并传递一些数据。

试着没有运气

XIB文件

#import "IncomingMessageCell.h"

@implementation IncomingMessageCell

- (void)awakeFromNib {

    UIImage * balloonImage = [UIImage imageNamed:@"bubble-left"];
    balloonImage = [balloonImage resizableImageWithCapInsets:(UIEdgeInsets){36, 32, 18, 12}];
    self.bubbleView.image = balloonImage;

    self.avatarView.layer.cornerRadius = 25;
    self.avatarView.clipsToBounds = YES;

    self.avatarView.userInteractionEnabled = YES;

    UITapGestureRecognizer *tapGesture1 = [[UITapGestureRecognizer alloc] initWithTarget:self  action:@selector(tapGesture:)];

    tapGesture1.numberOfTapsRequired = 1;

    [tapGesture1 setDelegate:self];

    [self.avatarView addGestureRecognizer:tapGesture1];
    }

- (void) tapGesture: (id)sender
{
    UIViewController *vc = [[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil] instantiateViewControllerWithIdentifier:@"yourVcIdentifier"];
[self.navigationController pushViewController:vc animated:YES];
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end

这怎么可能?

1 个答案:

答案 0 :(得分:0)

在ViewController中使用此单元格保存tableview。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    IncomingMessageCell *cell = ...;
    cell.avatarView.userInteractionEnabled = YES;

    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture:)];
    tapGesture.numberOfTapsRequired = 1;
   [cell.avatarView addGestureRecognizer:tapGesture];
    cell.avatarView.tag = 500 + indexPath.row;  // To detect cell that image belongs to, because you use dequeue cell
    return cell;
}

- (IBAction)handleTapGesture:(UITapGestureRecognizer *)tapGesture{
    //Do you action
    NSLog(@"Row tap : %ld",tapGesture.view.tag - 500);
    UIViewController *vc = [[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil] instantiateViewControllerWithIdentifier:@"yourVcIdentifier"];
    [self.navigationController pushViewController:vc animated:YES];
}