UIButton适用于模拟器,但不适用于设备

时间:2011-03-07 09:43:07

标签: iphone objective-c ios4 uibutton

我的UIButton在模拟器中运行完美,但在iOS4的iPhone上运行

picButton = [[UIButton alloc] initWithFrame:CGRectMake(165, 80, 90, 150)];
[picButton addTarget:self action:@selector(mailIt:) forControlEvents:UIControlEventTouchUpInside];
[picButton setBackgroundImage:[UIImage imageNamed:@"save_2.png"]  forState:UIControlStateNormal];
[picButton setBackgroundImage:[UIImage imageNamed:@"save_2.png"]  forState:UIControlStateSelected];

在iPhone上按钮显示正确,看起来已按下,但动作未启动。

稍后编辑: 这是mailIt:

的代码
-(IBAction) mailIt : (id)delegate{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:@"title!"];
NSString *emailBody = [NSString stringWithFormat:@"messagestring", imagename];
[picker setMessageBody:emailBody isHTML:YES];
[self presentModalViewController:picker animated:YES];
[picker release];
}

2 个答案:

答案 0 :(得分:1)

我认为您应该检查您的设备是否配置为发送邮件,因为您使用的是MFMailComposeViewController,但是您没有检查代码是否能够使用canSendMail方法显示视图。

要将设备配置为发送邮件,您需要启动邮件应用并设置电子邮件。

答案 1 :(得分:0)

picker.mailComposeDelegate = self;

应该是

picker.mailComposeDelegate = camera;