2

I have built a "teacher directory" of sorts, I have the data fill into 3 fields, name, position, and email. All of the fields are UILabels. How do I make it so that you can click on the email and it opens a blank email?

    @interface PersonDetailTableViewController ()

@end

@implementation PersonDetailTableViewController

@synthesize fnameLabel, snameLabel, emailLabel, person;

- (void)viewDidLoad
{
    [super viewDidLoad];

    [super viewDidLoad];

    self.fnameLabel.text = self.person.fname;
    self.snameLabel.text = self.person.sname;
    self.emailLabel.text = self.person.email;
}

(this is the table view controller where the data is being displayed)

user2918086
  • 265
  • 1
  • 2
  • 7

2 Answers2

0

Use a button with a transparent background (UIButtonTypeCustom)

In your viewDidLoad use:

[self.btnLabel addTarget:self action:@selector(btnLabelTouch:) forControlEvents:UIControlEventTouchUpInside];
self.btnLabel.titleLabel.text = @"text";

Button action:

- (IBAction)btnLabelTouch:(id)sender
{
    //open email code here//
}
RyanG
  • 4,393
  • 2
  • 39
  • 64
0

You can use a UITapGestureRecognizer. Add this to viewDidLoad:

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap)];
[self.fnameLabel addGestureRecognizer:tap];
tap.numberOfTapsRequired = 1;
tap.cancelsTouchesInView = NO;

Next add a new method:

-(void)tap
{
     //Do whatever
}
Abdullah Shafique
  • 6,878
  • 8
  • 35
  • 70