2016-04-27 5 views
0

Ich verwende eine Bibliothek, die eine xib Datei in Objective-c zu ViewcontrollerProgramatically segue aus xib-Datei erstellen in Storyboard

Ich habe meine Storyboard hat, dass ein zügiges Klasse

I segue von diesem xib erstellen müssen muss Datei in mein Storyboard und gebe einige Daten weiter.

dies ohne Glück versucht

XIB Datei

#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 

Wie ist das möglich?

+0

wo versuchst du das? und was ist deine aktuelle VC? –

+0

Ich habe meine Frage aktualisiert –

+0

Also was passiert, wenn Sie tippen? –

Antwort

0

Tun Sie dies in ViewController, die Tabellenansicht mit dieser Zelle enthält.

- (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]; 
} 
+0

Ich kann schon mit dem Klick umgehen, aber ich weiß nicht, wie man zum Hauptstoryboard übergeht –

+0

Ja, aber um segue zu behandeln, sollten Sie Ihren Code in ViewController nicht in Zelle setzen. Versuchen Sie, meine Art und Weise, können Sie Ihren Code setzen, die zu einer anderen Ansicht drücken: '- (IBAction) handleCellBtnClicked: (UIButton *) sender {// Haben Sie Aktion UIViewController * vc = [[UIStoryboard storyboardWithName: @" MainStoryboard "bundle: nil] instantiateViewControllerWithIdentifier: @" yourVcIdentifier "]; [self.navigationController pushViewController: vc animiert: YES]; } ' –

+0

können wir Tabgesture von CellForRowAtIndexPath verwenden? –

Verwandte Themen