我知道为什么我得到以下代码“控制可能达到非空函数结束”的2个错误?我让它在一个单独的应用程序中工作,但由于某种原因现在想出了这个错误。
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
switch (pickerView.tag) {
case kCATEGORYTYPEPICKERTAG:
return [categoryTypes count];;
break;
case kLOCATIONTYPEPICKERTAG:
return [locationTypes count];
break;
case kORIGINATORTYPEPICKERTAG:
return [originatorTypes count];
break;
case kDESTINATIONTYPEPICKERTAG:
return [destinationTypes count];
break;
case kSTATUSTYPEPICKERTAG:
return [statusTypes count];
break;
default:
break;
}
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
switch (pickerView.tag) {
case kCATEGORYTYPEPICKERTAG:
return [categoryTypes objectAtIndex:row];
break;
case kLOCATIONTYPEPICKERTAG:
return [locationTypes objectAtIndex:row];
break;
case kORIGINATORTYPEPICKERTAG:
return [originatorTypes objectAtIndex:row];
break;
case kDESTINATIONTYPEPICKERTAG:
return [destinationTypes objectAtIndex:row];
break;
case kSTATUSTYPEPICKERTAG:
return [statusTypes objectAtIndex:row];
break;
default:
break;
}
}
非常感谢
更新
完整代码:
@synthesize nameTextField, emailTextField, dateTextField, timeTextField, blankTextField, blankbTextField, mlabelcategory, messageTextView;
@synthesize name, emailaddress, date, time, blank, blankb, category, message;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
categoryTypes = [[NSArray alloc] initWithObjects:@"Appetizers",@"Breakfast",@"Dessert",@"Drinks",
@"Main Dish/Entree", @"Salad", @"Side Dish", @"Soup", @"Snack",
@"Baby Food", @"Pet Food",nil];
locationTypes = [[NSArray alloc] initWithObjects:@"African",@"American",@"Armenian",@"Barbecue",
@"Brazilian", @"British", @"Cajun", @"Central American", @"Chicken",
@"Chinese", @"Cuban",
@"Ethiopian", @"French", @"Greek", @"German", @"Hamburgers",
@"Homestyle Cooking", @"Indian", @"Irish", @"Italian", @"Jamaican",
@"Japanese", @"Korean", @"Mexican", @"Middle Eastern", @"Pakistani",
@"Pancakes /Waffles", @"Persian", @"Pizza", @"Polynesian", @"Russian",
@"Sandwiches", @"Seafood", @"Scandinavian", @"Spanish", @"Soul Food",
@"South American", @"Steak", @"Vegetarian", @"Tex-Mex", @"Thai",
@"Vietnamese",@"Wild Game",nil];
originatorTypes = [[NSArray alloc] initWithObjects:@"African",@"American",@"Armenian",@"Barbecue",
@"Brazilian", @"British", @"Cajun", @"Central American", @"Chicken",
@"Chinese", @"Cuban",
@"Ethiopian", @"French", @"Greek", @"German", @"Hamburgers",
@"Homestyle Cooking", @"Indian", @"Irish", @"Italian", @"Jamaican",
@"Japanese", @"Korean", @"Mexican", @"Middle Eastern", @"Pakistani",
@"Pancakes /Waffles", @"Persian", @"Pizza", @"Polynesian", @"Russian",
@"Sandwiches", @"Seafood", @"Scandinavian", @"Spanish", @"Soul Food",
@"South American", @"Steak", @"Vegetarian", @"Tex-Mex", @"Thai",
@"Vietnamese",@"Wild Game",nil];
destinationTypes = [[NSArray alloc] initWithObjects:@"African",@"American",@"Armenian",@"Barbecue",
@"Brazilian", @"British", @"Cajun", @"Central American", @"Chicken",
@"Chinese", @"Cuban",
@"Ethiopian", @"French", @"Greek", @"German", @"Hamburgers",
@"Homestyle Cooking", @"Indian", @"Irish", @"Italian", @"Jamaican",
@"Japanese", @"Korean", @"Mexican", @"Middle Eastern", @"Pakistani",
@"Pancakes /Waffles", @"Persian", @"Pizza", @"Polynesian", @"Russian",
@"Sandwiches", @"Seafood", @"Scandinavian", @"Spanish", @"Soul Food",
@"South American", @"Steak", @"Vegetarian", @"Tex-Mex", @"Thai",
@"Vietnamese",@"Wild Game",nil];
statusTypes = [[NSArray alloc] initWithObjects:@"African",@"American",@"Armenian",@"Barbecue",
@"Brazilian", @"British", @"Cajun", @"Central American", @"Chicken",
@"Chinese", @"Cuban",
@"Ethiopian", @"French", @"Greek", @"German", @"Hamburgers",
@"Homestyle Cooking", @"Indian", @"Irish", @"Italian", @"Jamaican",
@"Japanese", @"Korean", @"Mexican", @"Middle Eastern", @"Pakistani",
@"Pancakes /Waffles", @"Persian", @"Pizza", @"Polynesian", @"Russian",
@"Sandwiches", @"Seafood", @"Scandinavian", @"Spanish", @"Soul Food",
@"South American", @"Steak", @"Vegetarian", @"Tex-Mex", @"Thai",
@"Vietnamese",@"Wild Game",nil];
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
nameTextField.text = nil;
emailTextField.text = nil;
dateTextField.text = nil;
timeTextField.text = nil;
blankTextField.text = nil;
blankbTextField.text = nil;
mlabelcategory.text = nil;
messageTextView.text = nil;
categoryTypePicker = [[UIPickerView alloc] initWithFrame:CGRectMake(300,400,400,160)];
categoryTypePicker.tag = kCATEGORYTYPEPICKERTAG;
categoryTypePicker.showsSelectionIndicator = TRUE;
categoryTypePicker.dataSource = self;
categoryTypePicker.delegate = self;
categoryTypePicker.hidden = YES;
locationTypePicker = [[UIPickerView alloc] initWithFrame:CGRectMake(0,250,400,160)];
locationTypePicker.backgroundColor = [UIColor blueColor];
locationTypePicker.tag = kLOCATIONTYPEPICKERTAG;
locationTypePicker.showsSelectionIndicator = TRUE;
locationTypePicker.hidden = YES;
locationTypePicker.dataSource = self;
locationTypePicker.delegate = self;
originatorTypePicker = [[UIPickerView alloc] initWithFrame:CGRectMake(0,250,400,160)];
originatorTypePicker.backgroundColor = [UIColor blueColor];
originatorTypePicker.tag = kORIGINATORTYPEPICKERTAG;
originatorTypePicker.showsSelectionIndicator = TRUE;
originatorTypePicker.hidden = YES;
originatorTypePicker.dataSource = self;
originatorTypePicker.delegate = self;
destinationTypePicker = [[UIPickerView alloc] initWithFrame:CGRectMake(0,250,400,160)];
destinationTypePicker.backgroundColor = [UIColor blueColor];
destinationTypePicker.tag = kDESTINATIONTYPEPICKERTAG;
destinationTypePicker.showsSelectionIndicator = TRUE;
destinationTypePicker.hidden = YES;
destinationTypePicker.dataSource = self;
destinationTypePicker.delegate = self;
statusTypePicker = [[UIPickerView alloc] initWithFrame:CGRectMake(0,250,400,160)];
statusTypePicker.backgroundColor = [UIColor blueColor];
statusTypePicker.tag = kSTATUSTYPEPICKERTAG;
statusTypePicker.showsSelectionIndicator = TRUE;
statusTypePicker.hidden = YES;
statusTypePicker.dataSource = self;
statusTypePicker.delegate = self;
}
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations.
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)eve
{
if ( !locationTypePicker.hidden) {
locationTypePicker.hidden = YES;
}
if ( !categoryTypePicker.hidden) {
categoryTypePicker.hidden = YES;
}
if ( !originatorTypePicker.hidden) {
originatorTypePicker.hidden = YES;
}
if ( !destinationTypePicker.hidden) {
destinationTypePicker.hidden = YES;
}
if ( !statusTypePicker.hidden) {
statusTypePicker.hidden = YES;
}
}
#pragma mark -
#pragma mark picker methods
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return kPICKERCOLUMN;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
switch (pickerView.tag) {
case kCATEGORYTYPEPICKERTAG:
return [categoryTypes count];;
break;
case kLOCATIONTYPEPICKERTAG:
return [locationTypes count];
break;
case kORIGINATORTYPEPICKERTAG:
return [originatorTypes count];
break;
case kDESTINATIONTYPEPICKERTAG:
return [destinationTypes count];
break;
case kSTATUSTYPEPICKERTAG:
return [statusTypes count];
break;
default: return nil; break;
}
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
switch (pickerView.tag) {
case kCATEGORYTYPEPICKERTAG:
return [categoryTypes objectAtIndex:row];
break;
case kLOCATIONTYPEPICKERTAG:
return [locationTypes objectAtIndex:row];
break;
case kORIGINATORTYPEPICKERTAG:
return [originatorTypes objectAtIndex:row];
break;
case kDESTINATIONTYPEPICKERTAG:
return [destinationTypes objectAtIndex:row];
break;
case kSTATUSTYPEPICKERTAG:
return [statusTypes objectAtIndex:row];
break;
default: return nil; break;
}
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
if (pickerView.tag == kCATEGORYTYPEPICKERTAG) {
NSString *categoryType = [categoryTypes objectAtIndex:[pickerView selectedRowInComponent:0]];
[categoryTypeBtn setTitle:categoryType forState:UIControlStateNormal];
}else if (pickerView.tag == kLOCATIONTYPEPICKERTAG) {
NSString *locationType = [locationTypes objectAtIndex:[pickerView selectedRowInComponent:0]];
[locationTypeBtn setTitle:locationType forState:UIControlStateNormal];
}else if (pickerView.tag == kORIGINATORTYPEPICKERTAG) {
NSString *originatorType = [originatorTypes objectAtIndex:[pickerView selectedRowInComponent:0]];
[originatorTypeBtn setTitle:originatorType forState:UIControlStateNormal];
}else if (pickerView.tag == kDESTINATIONTYPEPICKERTAG) {
NSString *destinationType = [destinationTypes objectAtIndex:[pickerView selectedRowInComponent:0]];
[destinationTypeBtn setTitle:destinationType forState:UIControlStateNormal];
}else if (pickerView.tag == kSTATUSTYPEPICKERTAG) {
NSString *statusType = [statusTypes objectAtIndex:[pickerView selectedRowInComponent:0]];
[statusTypeBtn setTitle:statusType forState:UIControlStateNormal];
}
}
-(IBAction) showLocationTypePicker{
if ( locationTypePicker.hidden) {
locationTypePicker.hidden = NO;
[self.view addSubview:locationTypePicker];
}
else {
locationTypePicker.hidden = NO;
[locationTypePicker removeFromSuperview];
}
if ( categoryTypePicker.hidden) {
categoryTypePicker.hidden = YES;
[self.view addSubview:categoryTypePicker];
}
else {
categoryTypePicker.hidden = YES;
[categoryTypePicker removeFromSuperview];
}
if ( originatorTypePicker.hidden) {
originatorTypePicker.hidden = YES;
[self.view addSubview:originatorTypePicker];
}
else {
originatorTypePicker.hidden = YES;
[originatorTypePicker removeFromSuperview];
}
if ( destinationTypePicker.hidden) {
destinationTypePicker.hidden = YES;
[self.view addSubview:destinationTypePicker];
}
else {
destinationTypePicker.hidden = YES;
[destinationTypePicker removeFromSuperview];
}
if ( statusTypePicker.hidden) {
statusTypePicker.hidden = YES;
[self.view addSubview:statusTypePicker];
}
else {
statusTypePicker.hidden = YES;
[statusTypePicker removeFromSuperview];
}
}
-(IBAction) showCategoryTypePicker{
if ( categoryTypePicker.hidden) {
categoryTypePicker.hidden = NO;
[self.view addSubview:categoryTypePicker];
}
else {
categoryTypePicker.hidden = NO;
[categoryTypePicker removeFromSuperview];
}
if ( locationTypePicker.hidden) {
locationTypePicker.hidden = YES;
[self.view addSubview:locationTypePicker];
}
else {
locationTypePicker.hidden = YES;
[locationTypePicker removeFromSuperview];
}
if ( originatorTypePicker.hidden) {
originatorTypePicker.hidden = YES;
[self.view addSubview:originatorTypePicker];
}
else {
originatorTypePicker.hidden = YES;
[originatorTypePicker removeFromSuperview];
}
if ( destinationTypePicker.hidden) {
destinationTypePicker.hidden = YES;
[self.view addSubview:destinationTypePicker];
}
else {
destinationTypePicker.hidden = YES;
[destinationTypePicker removeFromSuperview];
}
if ( statusTypePicker.hidden) {
statusTypePicker.hidden = YES;
[self.view addSubview:statusTypePicker];
}
else {
statusTypePicker.hidden = YES;
[statusTypePicker removeFromSuperview];
}
}
-(IBAction) showOriginatorTypePicker{
if ( originatorTypePicker.hidden) {
originatorTypePicker.hidden = NO;
[self.view addSubview:originatorTypePicker];
}
else {
originatorTypePicker.hidden = NO;
[originatorTypePicker removeFromSuperview];
}
if ( locationTypePicker.hidden) {
locationTypePicker.hidden = YES;
[self.view addSubview:locationTypePicker];
}
else {
locationTypePicker.hidden = YES;
[locationTypePicker removeFromSuperview];
}
if ( categoryTypePicker.hidden) {
categoryTypePicker.hidden = YES;
[self.view addSubview:categoryTypePicker];
}
else {
categoryTypePicker.hidden = YES;
[categoryTypePicker removeFromSuperview];
}
if ( destinationTypePicker.hidden) {
destinationTypePicker.hidden = YES;
[self.view addSubview:destinationTypePicker];
}
else {
destinationTypePicker.hidden = YES;
[destinationTypePicker removeFromSuperview];
}
if ( statusTypePicker.hidden) {
statusTypePicker.hidden = YES;
[self.view addSubview:statusTypePicker];
}
else {
statusTypePicker.hidden = YES;
[statusTypePicker removeFromSuperview];
}
}
-(IBAction) showDestinationTypePicker{
if ( destinationTypePicker.hidden) {
destinationTypePicker.hidden = NO;
[self.view addSubview:destinationTypePicker];
}
else {
destinationTypePicker.hidden = NO;
[destinationTypePicker removeFromSuperview];
}
if ( locationTypePicker.hidden) {
locationTypePicker.hidden = YES;
[self.view addSubview:locationTypePicker];
}
else {
locationTypePicker.hidden = YES;
[locationTypePicker removeFromSuperview];
}
if ( originatorTypePicker.hidden) {
originatorTypePicker.hidden = YES;
[self.view addSubview:originatorTypePicker];
}
else {
originatorTypePicker.hidden = YES;
[originatorTypePicker removeFromSuperview];
}
if ( categoryTypePicker.hidden) {
categoryTypePicker.hidden = YES;
[self.view addSubview:categoryTypePicker];
}
else {
categoryTypePicker.hidden = YES;
[categoryTypePicker removeFromSuperview];
}
if ( statusTypePicker.hidden) {
statusTypePicker.hidden = YES;
[self.view addSubview:statusTypePicker];
}
else {
statusTypePicker.hidden = YES;
[statusTypePicker removeFromSuperview];
}
}
-(IBAction) showStatusTypePicker{
if ( statusTypePicker.hidden) {
statusTypePicker.hidden = NO;
[self.view addSubview:statusTypePicker];
}
else {
statusTypePicker.hidden = NO;
[statusTypePicker removeFromSuperview];
}
if ( locationTypePicker.hidden) {
locationTypePicker.hidden = YES;
[self.view addSubview:locationTypePicker];
}
else {
locationTypePicker.hidden = YES;
[locationTypePicker removeFromSuperview];
}
if ( originatorTypePicker.hidden) {
originatorTypePicker.hidden = YES;
[self.view addSubview:originatorTypePicker];
}
else {
originatorTypePicker.hidden = YES;
[originatorTypePicker removeFromSuperview];
}
if ( destinationTypePicker.hidden) {
destinationTypePicker.hidden = YES;
[self.view addSubview:destinationTypePicker];
}
else {
destinationTypePicker.hidden = YES;
[destinationTypePicker removeFromSuperview];
}
if ( categoryTypePicker.hidden) {
categoryTypePicker.hidden = YES;
[self.view addSubview:categoryTypePicker];
}
else {
categoryTypePicker.hidden = YES;
[categoryTypePicker removeFromSuperview];
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
#pragma - getting info from the UI
//NSString *test = nil;
- (IBAction)checkData:(id)sender
{
/*
name = nameTextField.text;
surname = surnameTextField.text;
bornDate = bornDateTextField.text;
address = addressTextField.text;
zipCode = zipTextField.text;
email = emailTextField.text;
*/
//NSLog(@" Name: %@ \n Surname: %@ \n Date of Birth: %@ \n Address: %@ \n Post Code: %@ \n email: %@ \n", name, surname, bornDate, address, zipCode, email);
unsigned int x,a = 0;
NSMutableString *emailmessage; //stringa variabile
emailmessage = [NSMutableString stringWithFormat: @""]; //le stringhe mutabili vanno inizializzate in questo modo!
for (x=0; x<7; x++)
{
switch (x) {
case 0:
if (nameTextField.text == nil) {
[emailmessage appendString:@"Name, "];
a=1;
}
break;
case 1:
if (emailTextField.text == nil)
{
[emailmessage appendString:@"Email Address, "];
a=1;
}
break;
case 2:
if (dateTextField.text == nil)
{
[emailmessage appendString:@"Date of Near Miss, "];
a=1;
}
break;
case 3:
if (timeTextField.text == nil)
{
[emailmessage appendString:@"Time of Near Miss, "];
a=1;
}
break;
case 4:
if (blankTextField.text == nil)
{
[emailmessage appendString:@"Post Code, "];
a=1;
}
break;
case 5:
if (blankbTextField.text == nil)
{
[emailmessage appendString:@"Email, "];
a=1;
}
break;
case 6:
if (mlabelcategory.text == nil)
{
[emailmessage appendString:@"Category, "];
a=1;
}
break;
case 7:
if (messageTextView.text == nil)
{
[emailmessage appendString:@"Observation Description, "];
a=1;
}
break;
default:
break;
}
}
NSLog (@"Email Message: %@", emailmessage);
if (a == 1) {
NSMutableString *popupError;
popupError = [NSMutableString stringWithFormat: @"Per inviare compilare i seguenti campi: "];
[popupError appendString:emailmessage]; //aggiungo i miei errori
[popupError appendString: @" grazie della comprensione."]; //
NSLog(@"%@", popupError);
UIAlertView *chiamataEffettuata = [[UIAlertView alloc]
initWithTitle:@"ATTENTION" //titolo del mio foglio
message:popupError
delegate:self
cancelButtonTitle:@"Ok, correggo" //bottone con cui si chiude il messaggio
otherButtonTitles:nil, nil];
[chiamataEffettuata show]; //istanza per mostrare effettivamente il messaggio
}
else
{
name = nameTextField.text;
emailaddress = emailTextField.text;
date = dateTextField.text;
time = timeTextField.text;
blank = blankTextField.text;
blankb = blankbTextField.text;
category = mlabelcategory.text;
message = messageTextView.text;
NSMutableString *nearmissreport;
nearmissreport = [NSMutableString stringWithFormat: @"<br><br> <b>Name:</b> %@ <br> <b>Email Address:</b> %@ <br> <b>Date of Near Miss:</b> %@ <br> <b>Time of Near Miss:</b> %@ <br> <b>Post Code:</b> %@ <br> <b>Email Address:</b> %@ <br> <b>Category:</b> %@ <br><b>Observation Description:</b> %@ <br>", name, emailaddress, date, time, blank, blankb, category, message];
NSLog(@"Near Miss Report: %@", nearmissreport);
NSMutableString *testoMail;
testoMail = [NSMutableString stringWithFormat: nearmissreport];
NSLog(@"%@", testoMail);
//MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject: name];
// Set up the recipients.
NSArray *toRecipients = [NSArray arrayWithObjects:@"paul.haddell@bbmmjv.com",nil];
//NSArray *ccRecipients = [NSArray arrayWithObjects:@"second@example.com",@"third@example.com", nil];
//NSArray *bccRecipients = [NSArray arrayWithObjects:@"four@example.com",nil];
[picker setToRecipients:toRecipients];
//[picker setCcRecipients:ccRecipients];
//[picker setBccRecipients:bccRecipients];
// Attach an image to the email.
//NSString *path = [[NSBundle mainBundle] pathForResource:@"ipodnano" ofType:@"png"];
//NSData *myData = [NSData dataWithContentsOfFile:path];
//[picker addAttachmentData:myData mimeType:@"image/png" fileName:@"ipodnano"];
// Fill out the email body text.
//NSMutableString *emailBody;
testoMail = [NSMutableString stringWithFormat: @"%@", testoMail];
[picker setMessageBody:testoMail isHTML:YES]; //HTML!!!!!!
// Present the mail composition interface.
[self presentViewController:picker animated:YES completion:nil];
}
}
// The mail compose view controller delegate method
- (void)mailComposeController:(MFMailComposeViewController *)controller
didFinishWithResult:(MFMailComposeResult)result
error:(NSError *)error
{
[self dismissModalViewControllerAnimated:YES];
}
#pragma mark - Mandare email
/*
- (void)sendMail:(NSMutableString*)testoMail{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:@"Reclutamento pompieri"];
// Set up the recipients.
NSArray *toRecipients = [NSArray arrayWithObjects:@"reda.bousbah@gmail.com",nil];
//NSArray *ccRecipients = [NSArray arrayWithObjects:@"second@example.com",@"third@example.com", nil];
//NSArray *bccRecipients = [NSArray arrayWithObjects:@"four@example.com",nil];
[picker setToRecipients:toRecipients];
//[picker setCcRecipients:ccRecipients];
//[picker setBccRecipients:bccRecipients];
// Attach an image to the email.
//NSString *path = [[NSBundle mainBundle] pathForResource:@"ipodnano" ofType:@"png"];
//NSData *myData = [NSData dataWithContentsOfFile:path];
//[picker addAttachmentData:myData mimeType:@"image/png" fileName:@"ipodnano"];
// Fill out the email body text.
NSString *emailBody = @"It is raining in sunny California!";
[picker setMessageBody:emailBody isHTML:NO];
// Present the mail composition interface.
[self presentViewController:picker animated:YES completion:nil];
}
*/
#pragma mark - methods to control the keyboard
- (IBAction)backgroundTap:(id)sender //method for resign the keyboard when the background is tapped
{
[nameTextField resignFirstResponder];
[emailTextField resignFirstResponder];
[dateTextField resignFirstResponder];
[timeTextField resignFirstResponder];
[blankTextField resignFirstResponder];
[blankbTextField resignFirstResponder];
[mlabelcategory resignFirstResponder];
[messageTextView resignFirstResponder];
}
- (IBAction)doneButtonPressed:(id)sender
{
NSLog( @"done button pressed");
[sender resignFirstResponder];
}
答案 0 :(得分:3)
这种情况发生的原因是,如果您标记的属性不属于任何情况,则会转到default
块,而后者又无法返回任何内容。
您需要在默认块中返回默认值(nil
,0
):
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
NSInteger numberOfRows = 0;
switch (pickerView.tag) {
case kCATEGORYTYPEPICKERTAG: {
numberOfRows = [categoryTypes count];
break;
}
case kLOCATIONTYPEPICKERTAG: {
numberOfRows = [locationTypes count];
break;
}
case kORIGINATORTYPEPICKERTAG: {
numberOfRows = [originatorTypes count];
break;
}
case kDESTINATIONTYPEPICKERTAG: {
numberOfRows = [destinationTypes count];
break;
}
case kSTATUSTYPEPICKERTAG: {
numberOfRows = [statusTypes count];
break;
}
default: {
break;
}
}
return numberOfRows;
}
您还必须使用titleForRow
方法执行此操作。
此外:
我更喜欢拥有最少量的returns
并修改一个值
相反,我将在最后返回
在[{1}}。