-1

我已经建立了一个目录。有133人。我有三个标签。“姓名”、“职位”和“电子邮件”。我如何使电子邮件标签充当按钮以打开带有标签地址的空白电子邮件?我遇到的问题是标签是动态的,我无法设置它。我是初学者,所以任何帮助将不胜感激!

这是.h文件-

@interface PersonDetailControllerViewController : UIViewController

@property(weak) IBOutlet UILabel *name;
@property(weak) IBOutlet UILabel *position;
@property(weak) IBOutlet UILabel *email;

@property(strong) Person *person;

@end

这是 .m 文件-

#import "PersonDetailControllerViewController.h"

@interface PersonDetailControllerViewController ()

@end

@implementation PersonDetailControllerViewController

@synthesize name, position, email, person;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
    // Custom initialization
}
return self;
}

- (void)viewDidLoad
{
[super viewDidLoad];

self.name.text = self.person.name;
self.position.text = self.person.position;
self.email.text = self.person.email;

// Do any additional setup after loading the view.
}

@end
4

2 回答 2

2

AUIButton包含一个名为的属性titleLabel,它实际上是 a UILabel,因此您不需要使用 a UILabel,您可以简单地使用 a UIButton。添加按钮后,您要做的是使用方法- (void)setTitle:(NSString *)title forState:(UIControlState)state. 这会将属性设置为您在传递它titleLabel时指定的任何内容。NSString

编辑:如果您死心塌地UILabel为此使用 a ,您可以执行以下操作:

UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
label.text = @"My Label";
label.userInteractionEnabled = YES;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(alert)];
[label addGestureRecognizer:tap];

然后在你的方法中,做任何你想做的事情。在我的情况下alert定义为:

- (void)alert
{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Hello" message:nil delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
    [alert show];
}
于 2013-10-27T22:23:34.270 回答
0

好的,基本上你需要做的是创建另一个viewController,这将是一个通用页面,将根据所选的教师进行填充。当用户点击 tableView 中的一行时,您应该转换到 detailView。有很多方法可以进行这种过渡(程序上,Storyboard segues 等),但这里有一个例子:

TeacherDetailViewController *controller = [TeacherDetailViewController alloc] init];
controller.teacher = array[indexPath.row];

其中教师是@property(nonatomic, strong) Person *person;该新班级的财产 () TeacherDetailViewController。通过设置teacher 属性,然后转换到新班级,新班级将从person所选对象中获取信息。

TeacherDetailViewController课堂上,您将设置包含电子邮件按钮的视图,并且在 中viewDidLoad,您将拥有:

-(void)viewDidLoad {
    teacherName.text = self.person.name;

}

然后我会在那个班上有一个按钮,上面写着给老师发邮件,这个按钮应该链接到一个动作方法,看起来像这样:

-(void)sendEmail {
 MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init];
mailViewController.mailComposeDelegate = self;
[mailViewController setToRecipients:self.teacher.email];

[mailViewController setSubject:@"Subject Goes Here."];
[mailViewController setMessageBody:@"Your message goes here." isHTML:NO];

[self presentModalViewController:mailViewController animated:YES];

}

于 2013-10-27T23:19:44.003 回答