iOS "Control may reach end of non-void function" - ios

Any idea why I am getting 2 errors of the below code of "Control may reach end of non-void function"? I had it working in a separate app but for some reason coming up with this error now.
- (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;
}
}
Many Thanks
UPDATE
Full code:
#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];
}

This happens because in case you tag property doesn't fall into any of the cases, it goes to the default block which in turn won't return anything.
You need to return a default value (nil,0) in the default block:
- (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;
}
You'll also have to do this in the titleForRow method.
Also:
I prefer having minimal amount of returns and modifying a value
instead which I will return at the end
Enclosing cases in {}.

Related

Button is on some devices visible and on some devices not visible

A button in a tablecell is visible, when a check is true and not visible, when the check is false.
Here are the part of the function:
BOOL checked = [self checkObjekt:object];
if (checked == YES ) {
[cell.buttonUpload setHidden:NO];
[cell.buttonUpload setTitle:#"Geprüft, Upload!" forState:UIControlStateNormal];
[cell.buttonUpload setEnabled:YES];
} else {
[cell.buttonUpload setHidden:YES];
[cell.buttonUpload setTitle:#"Ungeprüft" forState:UIControlStateNormal];
[cell.buttonUpload setEnabled:NO];
}
I have proofed if the data from the object are correct. And in all databases are the value are true or yes, so the button should be visible. With the same database-file are only on some devices are the button not visible.
All Devices are on iOS 8.1.3 and they are iPad mini Retina.
Here is the full function:
- (void)configureCell:(MbsStartCell *)cell atIndexPath:(NSIndexPath *)indexPath
{
Objekt *object = [self.fetchedResultsController objectAtIndexPath:indexPath];
NSDate *rawDate = [object valueForKey:#"termin"];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:#"dd.MM.yyyy"];
NSString *strLabelUhrzeitbis;
if (nil != object.uhrzeitbis && ![object.uhrzeitbis isEqualToString:#""])
{
strLabelUhrzeitbis = object.uhrzeitbis;
cell.labelDatum.text = [NSString stringWithFormat:#"%# zwischen %# und %#", [dateFormatter stringFromDate:rawDate], object.uhrzeit, strLabelUhrzeitbis];
}
else
{
cell.labelDatum.text = [NSString stringWithFormat:#"%# um %#", [dateFormatter stringFromDate:rawDate], object.uhrzeit];
}
NSSet *adressen = object.adressen;
NSArray *adressenArray = [adressen allObjects];
for (Adresse *adresse in adressenArray)
{
if ([adresse.typ isEqualToString:#"Baustelle"])
{
if (adresse.anschrift1 && ![adresse.anschrift1 isEqualToString:#""])
{
cell.labelAnschrift.text = [NSString stringWithFormat:#"%#", adresse.anschrift2];
} else {
cell.labelAnschrift.text = adresse.anschrift2;
}
cell.labelStrassePlzOrt.text = [NSString stringWithFormat:#"%#, %# %#", adresse.strasse, adresse.plz, adresse.ort];
}
}
cell.labelObjektnummer.text = [[object valueForKey:#"objektnr"] description];
cell.labelFilale.text = [NSString stringWithFormat:#"Filiale: %#, %#", object.filialname, object.objektanleger];
cell.labelAnrufer.text = [NSString stringWithFormat:#"Anrufer: %#", object.anrufer];
NSDate *rawSchadenstag = [object valueForKey:#"schadentag"];
NSDateFormatter *dateFormatterSchadenstag = [[NSDateFormatter alloc] init];
[dateFormatterSchadenstag setDateFormat:#"dd.MM.yyyy"];
cell.labelSchadentag.text = [NSString stringWithFormat:#"Schadenstag: %#", [dateFormatterSchadenstag stringFromDate:rawSchadenstag]];
cell.labelSchadensursache.text = [NSString stringWithFormat:#"Schadensursache: %#", object.schadensursache];
cell.labelSchadensursache.lineBreakMode = NSLineBreakByWordWrapping;
cell.labelSchadensursache.numberOfLines = 2;
NSString *strWeitererHinweis;
if (nil != object.weitererhinweis)
{
strWeitererHinweis = object.weitererhinweis;
}
else
{
strWeitererHinweis = #"Es sind keine weiteren Hinweise vorhanden";
}
cell.labelWeitererHinweis.text = [NSString stringWithFormat:#"Weiterer Hinweis: %#", strWeitererHinweis];
cell.labelWeitererHinweis.numberOfLines = 3;
cell.labelWeitererHinweis.lineBreakMode = NSLineBreakByWordWrapping;
int intTerminart = [object.terminart intValue];
switch (intTerminart) {
case 1: {
cell.backgroundColor = [UIColor whiteColor];
[cell.buttonUpload setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
break;
}
case 2: {
cell.backgroundColor = [UIColor blueColor];
[cell.buttonUpload setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
break;
}
case 4: {
cell.backgroundColor = [UIColor redColor];
[cell.buttonUpload setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
break;
}
case 5: {
cell.backgroundColor = [UIColor yellowColor];
[cell.buttonUpload setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
break;
}
case 6: {
cell.backgroundColor = [UIColor greenColor];
[cell.buttonUpload setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
break;
}
default:
break;
}
cell.selectionStyle = UITableViewCellSelectionStyleGray;
BOOL checked = [self checkObjekt:object];
if (checked == YES ) {
[cell.buttonUpload setHidden:NO];
[cell.buttonUpload setTitle:#"Geprüft, Upload!" forState:UIControlStateNormal];
[cell.buttonUpload setEnabled:YES];
} else {
[cell.buttonUpload setHidden:NO];
[cell.buttonUpload setTitle:#"Ungeprüft" forState:UIControlStateNormal];
[cell.buttonUpload setEnabled:YES];
}
}
Here is the checkObjekt Function:
- (BOOL)checkObjekt:(Objekt *)objekt {
if ([[objekt.wohneinheiten allObjects] count] == 0) {
return NO;
}
//Das Schadensformular für jede Wohneinheit wird in einer Schleife durchgearbeitet
for (Wohneinheit *wohneinheit in [objekt.wohneinheiten allObjects])
{
MbsAppDelegate *delegate = (MbsAppDelegate *)[[UIApplication sharedApplication] delegate];
NSEntityDescription *entityDescription = nil;
//Auswahl der richtigen Tabelle anhand der Terminart
if ([objekt.terminart integerValue] == 1)
{
entityDescription = [NSEntityDescription entityForName:#"Schaden" inManagedObjectContext:delegate.managedObjectContext];
}
else if ([objekt.terminart integerValue] == 2)
{
entityDescription = [NSEntityDescription entityForName:#"Leckortung" inManagedObjectContext:delegate.managedObjectContext];
}
else if ([objekt.terminart integerValue] == 4)
{
entityDescription = [NSEntityDescription entityForName:#"Aufbau" inManagedObjectContext:delegate.managedObjectContext];
}
else if ([objekt.terminart integerValue] == 5)
{
entityDescription = [NSEntityDescription entityForName:#"Zwischenmessung" inManagedObjectContext:delegate.managedObjectContext];
}
else if ([objekt.terminart integerValue] == 6)
{
entityDescription = [NSEntityDescription entityForName:#"Abbau" inManagedObjectContext:delegate.managedObjectContext];
}
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:entityDescription];
NSPredicate *predicate = [NSPredicate predicateWithFormat:#"wohneinheit == %#", wohneinheit];
[request setPredicate:predicate];
NSError *error;
NSArray *items = [delegate.managedObjectContext executeFetchRequest:request error:&error];
if (items == nil || [items count] != 1)
{
//Wenn kein Schadens- oder Leckortungsformular vorhanden ist, dann wird NO zurückgegeben
return NO;
}
else
{
//Durchlaufen der einzelnen Checked Spalten.
for (id item in items) {
int tempChecked = 0;
NSArray *checkedColumns = nil;
if ([objekt.terminart integerValue] == 1)
{
checkedColumns = self.checkedColumnsTerminart1;
}
else if ([objekt.terminart integerValue] == 2)
{
checkedColumns = self.checkedColumnsTerminart2;
}
else if ([objekt.terminart integerValue] == 4)
{
checkedColumns = self.checkedColumnsTerminart4;
}
else if ([objekt.terminart integerValue] == 5)
{
checkedColumns = self.checkedColumnsTerminart5;
}
else if ([objekt.terminart integerValue] == 6)
{
checkedColumns = self.checkedColumnsTerminart6;
}
for (NSString *checkedColumn in checkedColumns)
{
NSManagedObject *managedObject = (NSManagedObject *)item;
NSDictionary * attributes = [[managedObject entity] attributesByName];
NSArray *allKeys = [attributes allKeys];
if ([allKeys containsObject:checkedColumn]) {
NSNumber *checkedColumnValue = (NSNumber *)[item valueForKey:checkedColumn];
if (checkedColumnValue != [NSNumber numberWithInt:1]) {
tempChecked = 0;
}
else
{
tempChecked = 1;
}
} else {
tempChecked = 1;
}
}
if(tempChecked == 0)
{
return NO;
}
else
{
return YES;
}
}
}
}
return YES;
}

iOS Multiple UIpickerView not showing Arrays

I have a hidden UIpickerView that should display a different Array depending on what button is pushed. The picker view shows up when the button is pushed but for some reason it doesn't show the Arrays in the picker view. I would be extremely grateful of any help!!!!
Here is the .m file:
#import "ViewController.h"
#import <MessageUI/MessageUI.h>
#import <MessageUI/MFMailComposeViewController.h>
#define GeoLocation TRUE // FALSE for no latitude/longitude information
#define kPICKERCOLUMN 1
typedef NS_ENUM(NSInteger, PickerType) {
CATEGORY_PICKER,
LOCATION_PICKER,
ORIGINATOR_PICKER,
DESTINATION_PICKER,
STATUS_PICKER
};
#define kPICKERCOLUMN 1
#define kPICKER_TAG 101
#interface ViewController ()
#end
#implementation ViewController
{
UIPickerView *picker;
PickerType pickerType;
}
#synthesize nameTextField, emailTextField, dateTextField, timeTextField, blankTextField, blankbTextField, mlabelcategory, messageTextView, categoryTypeBtn;
#synthesize name, emailaddress, date, time, blank, blankb, category, message, email, button;
- (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"
,nil];
originatorTypes = [[NSArray alloc] initWithObjects:#"African",#"American",#"Armenian",#"Barbecue",
nil];
destinationTypes = [[NSArray alloc] initWithObjects:#"African",#"American",#"Armenian",#"Barbecue",
nil];
statusTypes = [[NSArray alloc] initWithObjects:#"African",#"American",#"Armenian",#"Barbecue",
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;
picker = [[UIPickerView alloc] initWithFrame:CGRectMake(100,100,400,160)];
picker.showsSelectionIndicator = TRUE;
picker.dataSource = self;
picker.delegate = self;
picker.hidden = YES;
[self.view addSubview:picker];
}
/*
// 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
{
picker.hidden = YES;
}
#pragma mark -
#pragma mark picker methods
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return kPICKERCOLUMN;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
switch (pickerType) {
case CATEGORY_PICKER:
return [categoryTypes count];;
break;
case LOCATION_PICKER:
return [locationTypes count];
break;
case ORIGINATOR_PICKER:
return [originatorTypes count];
break;
case DESTINATION_PICKER:
return [destinationTypes count];
break;
case STATUS_PICKER:
return [statusTypes count];
break;
default: return -1;
break;
}
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
switch (pickerType) {
case CATEGORY_PICKER:
return [categoryTypes objectAtIndex:row];
break;
case LOCATION_PICKER:
return [locationTypes objectAtIndex:row];
break;
case ORIGINATOR_PICKER:
return [originatorTypes objectAtIndex:row];
break;
case DESTINATION_PICKER:
return [destinationTypes objectAtIndex:row];
break;
case STATUS_PICKER:
return [statusTypes objectAtIndex:row];
break;
default: return nil;
break;
}
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
switch (pickerType) {
case CATEGORY_PICKER: {
NSString *categoryType = [categoryTypes objectAtIndex:[pickerView selectedRowInComponent:0]];
[categoryTypeBtn setTitle:categoryType forState:UIControlStateNormal];
break;
}
case LOCATION_PICKER: {
NSString *locationType = [locationTypes objectAtIndex:[pickerView selectedRowInComponent:0]];
[locationTypeBtn setTitle:locationType forState:UIControlStateNormal];
break;
}
case ORIGINATOR_PICKER: {
NSString *originatorType = [originatorTypes objectAtIndex:[pickerView selectedRowInComponent:0]];
[originatorTypeBtn setTitle:originatorType forState:UIControlStateNormal];
break;
}
case DESTINATION_PICKER: {
NSString *destinationType = [destinationTypes objectAtIndex:[pickerView selectedRowInComponent:0]];
[destinationTypeBtn setTitle:destinationType forState:UIControlStateNormal];
break;
}
case STATUS_PICKER:{
NSString *statusType = [statusTypes objectAtIndex:[pickerView selectedRowInComponent:0]];
[statusTypeBtn setTitle:statusType forState:UIControlStateNormal];
break;
}
default:
break;
}
}
-(IBAction) showLocationTypePicker{
pickerType = LOCATION_PICKER;
picker.hidden = NO;
[picker reloadAllComponents];
}
-(IBAction) showCategoryTypePicker{
pickerType = CATEGORY_PICKER;
picker.hidden = NO;
[picker reloadAllComponents];
}
-(IBAction) showOriginatorTypePicker{
pickerType = ORIGINATOR_PICKER;
picker.hidden = NO;
[picker reloadAllComponents];
}
-(IBAction) showDestinationTypePicker{
pickerType = DESTINATION_PICKER;
picker.hidden = NO;
[picker reloadAllComponents];
}
-(IBAction) showStatusTypePicker{
pickerType = STATUS_PICKER;
picker.hidden = NO;
[picker reloadAllComponents];
}
- (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];
}
#end
Many Thanks

textFieldDidBeginEditing not fired at first tap

When i tap the textfield textFieldDidBeginEditing starts to be fired after second tap. When I remove below code and after inside the textFieldDidBeginEditing method. It is fired at first tap. How can I make it fired at first tap?
[numKeyboard.view setFrame:CGRectMake(0,
self.view.frame.size.height-numKeyboard.view.frame.size.height, 320,
320)];
.m file:
#import "MainViewController.h"
#import "HastaDAO.h"
#import "YatanHastaBilgileriDAO.h"
#import "SettingViewController.h"
#import "Global.h"
#import <AudioToolbox/AudioServices.h>
#import "AlerjiModel.h"
#import "AlerjiDAO.h"
#import "NumKeyboard.h"
#interface MainViewController ()
{
int whichbtn;
}
#end
#implementation MainViewController
#synthesize player=_player;
#synthesize resultText1, resultText2,result,closeResult;
NSMutableArray *favTani;
HastaModel *yatanHastaBilgisi;
NSString *currentKey,*sound;
NSString *currentStringValue;
HastaModel *hasta;
int compareResult;
NSString *string=#"";
NSInteger didCompare=1;
UIImage *img;
NSString *str1,*str2;
NSInteger fromHistory=0;
-(void)viewDidAppear:(BOOL)animated{
if(fromHistory){
self.resultText1.text=str1;
self.resultText2.text=str2;
}
}
+(void)set_from_view:(NSInteger)history scanner:(NSInteger)scanner{
fromHistory=history;
}
-(void)textFieldDidEndEditing:(UITextField *)textField{
if (textField == self.resultText2 && (![self.resultText1.text isEqualToString:#""] && ![self.resultText2.text isEqualToString:#""])){
[self destroyNumKeyboard];
[self compareTwoBarcode];
}
}
+(void)setResultTexts:(NSString*)str img:(UIImage*)image{
string=str;
img=[[UIImage alloc]init];
img=image;
}
-(void)compareTwoBarcode{
[self.resultText1 resignFirstResponder];
[self.resultText2 resignFirstResponder];
if(![self.resultText1.text isEqualToString:#""] && ![self.resultText2.text isEqualToString:#""] )
{
didCompare=1;
if ([resultText1.text isEqualToString:resultText2.text]) {
sound=#"%#/accept.mp3";
result.text = #"EŞLEŞİYOR";
result.backgroundColor = [UIColor colorWithRed:153/255.0 green:255/255.0 blue:51/255.0 alpha:0.85];
compareResult=1;
}
else
{
sound=#"%#/reject.mp3";
result.text = #"EŞLEŞMİYOR";
result.backgroundColor = [UIColor colorWithRed:255/255.0 green:0/255.0 blue:0/255.0 alpha:0.85];
compareResult=0;
}
[closeResult setHidden:FALSE];
[result setHidden:FALSE];
NSString *soundFilePath = [NSString stringWithFormat:sound, [[NSBundle mainBundle] resourcePath]];
NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath];
player = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFileURL error:nil];
player.numberOfLoops = 1; //Infinite
if([SettingViewController getVolume])
[player play];
if([SettingViewController getVibrate]){
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
}
}else{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Uyarı"
message:#"Barkod alanları dolu olmalıdır!"
delegate:nil
cancelButtonTitle:#"Tamam"
otherButtonTitles:nil];
[alert show];
}
}
-(void)setHistorySource{
NSString *word= self.resultText1.text;
NSString *pathhistory = [[self documentsDirectory] stringByAppendingPathComponent:#"history.plist"];
NSMutableArray *histList = [[NSMutableArray alloc] initWithContentsOfFile:pathhistory];
NSInteger ishist=0;
for (NSInteger i=[histList count]-1; i>=0;i--) {
NSDictionary *d = [histList objectAtIndex:i];
//NSString *patientName=[d objectForKey:#"PATIENT"];
NSString *name1=[d objectForKey:#"WORD1"];
NSString *name2=[d objectForKey:#"WORD2"];
if([name1 isEqualToString:self.resultText1.text] &&
[name2 isEqualToString:self.resultText2.text])
ishist=1;
}
if(ishist==0){
HastaModel*hmodel=[[HastaModel alloc]init];
NSMutableArray *arr=[HastaDAO getHasta:[self.resultText1.text intValue] yatanAyaktan:1];
if([arr count]==0)
arr=[HastaDAO getHasta:[self.resultText1.text intValue] yatanAyaktan:0];
if([arr count]){
hmodel=[arr objectAtIndex:0];
NSDictionary *dic=[NSDictionary dictionaryWithObjectsAndKeys:
hmodel.Ad, #"PATIENT",
self.resultText1.text, #"WORD1",
self.resultText2.text,#"WORD2",
[NSString stringWithFormat:#"%ld",(long)compareResult ],#"EQUAL",
nil];
[histList addObject:dic];
if(![word isEqual:#""])
[histList writeToFile:pathhistory atomically:TRUE];
}
}
}
- (BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation) interfaceOrientation{
return(YES);
}
+(void)setbarcode1:(NSString*)barcode1 barcode2:(NSString*)barcode2{
str1=barcode1;
str2=barcode2;
}
- (void)viewDidLoad{
[super viewDidLoad];
[self.resultText1 setDelegate:self];
[self.resultText2 setDelegate:self];
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
[textField resignFirstResponder];
return true;
}
-(void)textFieldDidBeginEditing:(UITextField *)textField{
//if(textField==self.resultText2 && !resultText2.isFirstResponder){
UIView *dummyView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1, 1)];
textField.inputView = dummyView;
int i=0;
for(UIViewController *vc in self.childViewControllers)
if([vc isKindOfClass:[NumKeyboard class]])
{
i++;
break;
}
if(!i){
NumKeyboard* numKeyboard = [[NumKeyboard alloc] initWithNibName:#"NumKeyboard" bundle:nil];
[numKeyboard.view setFrame:CGRectMake(0, self.view.frame.size.height-numKeyboard.view.frame.size.height, 320, 320)];
[self.view addSubview:numKeyboard.view];
[self addChildViewController:numKeyboard];
}
[self.view reloadInputViews];
//}
}
-(void)destroyNumKeyboard {
for(UIViewController *vc in self.childViewControllers){
if([vc isKindOfClass:[NumKeyboard class]])
{
[vc willMoveToParentViewController:nil];
[vc.view removeFromSuperview];
[vc removeFromParentViewController];
[self.parentViewController reloadInputViews];
}
break;
}
/*for (NumKeyboard *numKeyboardView in self.childViewControllers) {
if(numKeyboardView){
//UIButton son obje olduğu için
//[self.view.subviews.lastObject removeFromSuperview];
for (UIButton * btn in self.view.subviews) {
if([btn isKindOfClass:[UIButton class]])
if([btn.titleLabel.text isEqualToString:#"X"]){
[btn removeFromSuperview];
break;
}
}
[numKeyboardView willMoveToParentViewController:nil];
[numKeyboardView.view removeFromSuperview];
[numKeyboardView removeFromParentViewController];
[self reloadInputViews];
break;
}
}*/
}
- (void)didReceiveMemoryWarning{
[super didReceiveMemoryWarning];
}
-(void) closeHastaDetail{
[self.hastadetailview setHidden:TRUE];
}
-(void) closeHastaDetailDetail{
[self.hastadetailindetailview setHidden:TRUE];
}
-(void) openHastaDetailDetail{
[self.hastadetailindetailview setHidden:FALSE];
}
/*
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
if(textField.tag==2){
NSCharacterSet* numberCharSet = [NSCharacterSet characterSetWithCharactersInString:#"0123456789"];
for (int i = 0; i < [string length]; ++i)
{
unichar c = [string characterAtIndex:i];
if (![numberCharSet characterIsMember:c])
{
return NO;
}
}
}
return YES;
}*/
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict {
currentKey=elementName;
currentStringValue=nil;
}
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item{
if(tabBar.tag == 0)
{
[self closeHastaDetail];
[self closeHastaDetailDetail];
}
}
- (NSString *)documentsDirectory {
return [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES) lastObject];
}
+(void)setDidCompareZero{
didCompare=0;
}
- (IBAction)closehastadetail:(id)sender {
[self.hastadetailview setHidden:TRUE];
[self performSelector:#selector(setHistorySource) withObject:nil afterDelay:0.1f];
}
- (IBAction)push_CompareBtn:(id)sender {
[self compareTwoBarcode];
}
- (IBAction) closeResult:(id)sender{
[closeResult setHidden:TRUE];
[result setHidden:YES];
if([SettingViewController getTekliCokluArama]==1){
}
}
- (IBAction)del_txt1:(id)sender {
self.resultText1.text=#"";
}
- (IBAction)del_txt2:(id)sender {
self.resultText2.text=#"";
}
- (IBAction) deleteResult:(id)sender{
//[resultImage1 setImage: [UIImage imageNamed:#"img1.png"]];
resultText1.text = #"";
//[resultImage2 setImage:[UIImage imageNamed:#"img2.png"]];
resultText2.text = #"";
}
- (IBAction) okDetailBtn:(id)sender{
[self.hastadetailindetailview setHidden:TRUE];
}
- (IBAction) showDetail:(id)sender{
[MainViewController set_from_view:0 scanner:0];
[self openHastaDetailDetail];
}
- (IBAction)setHastaDetail:(id)sender {
[self closeHastaDetailDetail];
self.hastadetailview.contentSize =CGSizeMake(320, 600);
[self.hastadetailview setContentOffset:CGPointMake(self.hastadetailview.contentOffset.x, 0)
animated:YES];
if(hasta==nil)
hasta=[[HastaModel alloc]init];
if([self.resultText1.text length]>0){
NSMutableArray *arr=[HastaDAO getHasta:[self.resultText1.text intValue] yatanAyaktan:1];
if(![arr count] && ![self.resultText1.text isEqualToString:self.hastaProtokol.text])
arr=[HastaDAO getHasta:[self.resultText1.text intValue] yatanAyaktan:0];
if([arr count])
{
hasta =[arr objectAtIndex:0];
if(![self.resultText1.text isEqualToString:self.hastaProtokol.text])
yatanHastaBilgisi=[YatanHastaBilgileriDAO yatanHastaBilgileri:hasta.Id];
self.hastaAd.text=hasta.Ad;
self.hastaAd.textAlignment=NSTextAlignmentRight;
self.hastaAd.font=[UIFont systemFontOfSize:18];
self.hastaProtokol.text=[NSString stringWithFormat:#"%ld", (long)hasta.Id];
self.hastaBolum.text=hasta.Bolum;
self.hastaOda.text=hasta.Oda;
self.hastaCinsiyet.text=hasta.Cinsiyet;
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:#"dd-MM-yyyy"];
NSString *strDate = [dateFormatter stringFromDate:yatanHastaBilgisi.DogumTarihi];
self.hastaDogumTarihi.text=strDate;
self.hastaYatak.text=hasta.Yatak;
self.hastaDoktor.text=yatanHastaBilgisi.Doktor;
if(hasta.LastOrderId>0)
{
NSMutableArray *arr1= [AlerjiDAO alerji:0 orderId:hasta.LastOrderId];
NSString*hAlerji=#"";
for(AlerjiModel *item in arr1 )
{
if(![hAlerji isEqualToString:#""])
hAlerji=[NSString stringWithFormat:#"%#,%#",hAlerji,item.Ad];
else
hAlerji=item.Ad;
}
self.hastaAlerji.text = hAlerji;
}else
self.hastaAlerji.text =#"";
[self.hastadetailview setHidden:FALSE];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#""
message:#"Hasta bulunamadı."
delegate:nil
cancelButtonTitle:#"Tamam"
otherButtonTitles:nil];
[alert show];
}
}
}#end

iOS Multiple Picker Views "Parse issue: Expected Expression"

I have multiple pickerviews in 1 view control. It works fine with 2 picker views but when I add any more it comes up with 7 "Expected Expression" errors in the following code:
#pragma mark -
#pragma mark picker methods
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return kPICKERCOLUMN;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
if (pickerView.tag == kCATEGORYTYPEPICKERTAG)
return [categoryTypes count];
else
return [locationTypes count];
else
return [originatorTypes count];
else
return [destinationTypes count];
else
return [statusTypes count];
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
if (pickerView.tag == kCATEGORYTYPEPICKERTAG)
return [categoryTypes objectAtIndex:row];
else
return [locationTypes objectAtIndex:row];
else
return [originatorTypes objectAtIndex:row];
else
return [destinationTypes objectAtIndex:row];
else
return [statusTypes objectAtIndex:row];
}
- (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 {
NSString *locationType = [locationTypes objectAtIndex:[pickerView selectedRowInComponent:0]];
[locationTypeBtn setTitle:locationType forState:UIControlStateNormal];
}else {
NSString *originatorType = [originatorTypes objectAtIndex:[pickerView selectedRowInComponent:0]];
[originatorTypeBtn setTitle:originatorType forState:UIControlStateNormal];
}else {
NSString *destinationType = [destinationTypes objectAtIndex:[pickerView selectedRowInComponent:0]];
[destinationTypeBtn setTitle:destinationType forState:UIControlStateNormal];
}else {
NSString *statusType = [statusTypes objectAtIndex:[pickerView selectedRowInComponent:0]];
[statusTypeBtn setTitle:statusType forState:UIControlStateNormal];
}
}
All 7 errors are showing on the separate else lines.
Hopefully it's something simple that i'm missing out!!
Many thanks
UPDATE
I have all the picker views working now. However the only the only information that changes is the final button rather than each button depending on what is picked.
Here is the complete .m file:
#define kPICKERCOLUMN 1
#define kCATEGORYTYPEPICKERTAG 20
#define kLOCATIONTYPEPICKERTAG 21
#define kORIGINATORTYPEPICKERTAG 22
#define kDESTINATIONTYPEPICKERTAG 23
#define kSTATUSTYPEPICKERTAG 24
#implementation HomeViewController
// The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (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;
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
categoryTypePicker = [[UIPickerView alloc] initWithFrame:CGRectMake(0,250,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:
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;
}
}
- (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 ( categoryTypePicker.hidden) {
categoryTypePicker.hidden = NO;
[self.view addSubview:categoryTypePicker];
}
else {
categoryTypePicker.hidden = NO;
[categoryTypePicker removeFromSuperview];
}
if ( originatorTypePicker.hidden) {
originatorTypePicker.hidden = NO;
[self.view addSubview:originatorTypePicker];
}
else {
originatorTypePicker.hidden = NO;
[originatorTypePicker removeFromSuperview];
}
if ( destinationTypePicker.hidden) {
destinationTypePicker.hidden = NO;
[self.view addSubview:destinationTypePicker];
}
else {
destinationTypePicker.hidden = NO;
[destinationTypePicker removeFromSuperview];
}
if ( statusTypePicker.hidden) {
statusTypePicker.hidden = NO;
[self.view addSubview:statusTypePicker];
}
else {
statusTypePicker.hidden = NO;
[statusTypePicker removeFromSuperview];
}
}
-(IBAction) showCategoryTypePicker{
if ( locationTypePicker.hidden) {
locationTypePicker.hidden = NO;
[self.view addSubview:locationTypePicker];
}
else {
locationTypePicker.hidden = NO;
[locationTypePicker removeFromSuperview];
}
if ( originatorTypePicker.hidden) {
originatorTypePicker.hidden = NO;
[self.view addSubview:originatorTypePicker];
}
else {
originatorTypePicker.hidden = NO;
[originatorTypePicker removeFromSuperview];
}
if ( destinationTypePicker.hidden) {
destinationTypePicker.hidden = NO;
[self.view addSubview:destinationTypePicker];
}
else {
destinationTypePicker.hidden = NO;
[destinationTypePicker removeFromSuperview];
}
if ( statusTypePicker.hidden) {
statusTypePicker.hidden = NO;
[self.view addSubview:statusTypePicker];
}
else {
statusTypePicker.hidden = NO;
[statusTypePicker removeFromSuperview];
}
}
-(IBAction) showOriginatorTypePicker{
if ( locationTypePicker.hidden) {
locationTypePicker.hidden = NO;
[self.view addSubview:locationTypePicker];
}
else {
locationTypePicker.hidden = NO;
[locationTypePicker removeFromSuperview];
}
if ( categoryTypePicker.hidden) {
categoryTypePicker.hidden = NO;
[self.view addSubview:categoryTypePicker];
}
else {
categoryTypePicker.hidden = NO;
[categoryTypePicker removeFromSuperview];
}
if ( destinationTypePicker.hidden) {
destinationTypePicker.hidden = NO;
[self.view addSubview:destinationTypePicker];
}
else {
destinationTypePicker.hidden = NO;
[destinationTypePicker removeFromSuperview];
}
if ( statusTypePicker.hidden) {
statusTypePicker.hidden = NO;
[self.view addSubview:statusTypePicker];
}
else {
statusTypePicker.hidden = NO;
[statusTypePicker removeFromSuperview];
}
}
-(IBAction) showDestinationTypePicker{
if ( locationTypePicker.hidden) {
locationTypePicker.hidden = NO;
[self.view addSubview:locationTypePicker];
}
else {
locationTypePicker.hidden = NO;
[locationTypePicker removeFromSuperview];
}
if ( originatorTypePicker.hidden) {
originatorTypePicker.hidden = NO;
[self.view addSubview:originatorTypePicker];
}
else {
originatorTypePicker.hidden = NO;
[originatorTypePicker removeFromSuperview];
}
if ( categoryTypePicker.hidden) {
categoryTypePicker.hidden = NO;
[self.view addSubview:categoryTypePicker];
}
else {
categoryTypePicker.hidden = NO;
[categoryTypePicker removeFromSuperview];
}
if ( statusTypePicker.hidden) {
statusTypePicker.hidden = NO;
[self.view addSubview:statusTypePicker];
}
else {
statusTypePicker.hidden = NO;
[statusTypePicker removeFromSuperview];
}
}
-(IBAction) showStatusTypePicker{
if ( locationTypePicker.hidden) {
locationTypePicker.hidden = NO;
[self.view addSubview:locationTypePicker];
}
else {
locationTypePicker.hidden = NO;
[locationTypePicker removeFromSuperview];
}
if ( originatorTypePicker.hidden) {
originatorTypePicker.hidden = NO;
[self.view addSubview:originatorTypePicker];
}
else {
originatorTypePicker.hidden = NO;
[originatorTypePicker removeFromSuperview];
}
if ( destinationTypePicker.hidden) {
destinationTypePicker.hidden = NO;
[self.view addSubview:destinationTypePicker];
}
else {
destinationTypePicker.hidden = NO;
[destinationTypePicker removeFromSuperview];
}
if ( categoryTypePicker.hidden) {
categoryTypePicker.hidden = NO;
[self.view addSubview:categoryTypePicker];
}
else {
categoryTypePicker.hidden = NO;
[categoryTypePicker removeFromSuperview];
}
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc. that aren't in use.
}
- (void)viewDidUnload {
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[locationTypes release];
[categoryTypes release];
[originatorTypes release];
[destinationTypes release];
[statusTypes release];
[categoryTypePicker release];
[locationTypePicker release];
[originatorTypePicker release];
[destinationTypePicker release];
[statusTypePicker release];;
[super dealloc];
}
The syntax problem is straight forward: those else's need conditions, like:
if (pickerView.tag == kCATEGORYTYPEPICKERTAG)
return [categoryTypes count];
else if (pickerView.tag == kSOMEOTHERTAG_THAT_MEANS_USE_LOCATION_TYPES)
return [locationTypes count];
else if (// etc.
An if can have a single else with no condition. The implication is that the else condition is the complement of the if, i.e....
if (someCondition) {
// some statements
} else { // this implies: else if (!someCondition)
// some statements
}
But any more than one becomes ambiguous. A switch statement would be an even better choice...
switch (pickerView.tag) {
case kCATEGORYTYPEPICKERTAG:
return categoryTypes count];
break;
case kSOMEOTHERTAG_THAT_MEANS_USE_LOCATION_TYPES:
return [locationTypes count];
// etc
default:
break;
}
But I'm wondering if the logic makes sense, switching on picker view's tag. You would do this to distinguish between many picker views -- is that what you mean? Maybe the conditional branching should be done on what's been picked (selectedRow) in a single picker view?

Content not loading on horizontal scroll view

Hi I am building an app in which I want my contents to be displayed on a view which is horizontally scroll-able.
I have implemented the following code for it:
-(void)DownLoadData:(NSString *)indexSelect
{
self._parserForNewsDetail = [afaqsParser getInstance];
[[afaqsParser getInstance] setCacheNeed:TRUE];
[self._parserForNewsDetail parseWithUrl:[_arrUrlLinks objectAtIndex:[indexSelect integerValue]] UrlTypefor:nil];
NSDictionary *resultDic;
resultDic = [[[self._parserForNewsDetail getLinkAndIdDic] valueForKey:#"items"]objectAtIndex:0];
NSLog(#"Detail Dic = %#",[resultDic description]);
if (resultDic== NULL || resultDic ==nil)
{
//Check internet here
[[SharedUtilities getInstance]RemoveActivityIndicatorView];
[SharedUtilities ShowAlert:#"No Data Found" title:nil withView:self.view];
return;
}
[self performSelectorOnMainThread:#selector(SetValuesInUserInterface:) withObject: resultDic waitUntilDone:NO];
[[SharedUtilities getInstance]RemoveActivityIndicatorView];
}
-(void)DownloadNext:(NSString *)indexSelect
{
resultDic = [[[self._parserForNewsDetail getLinkAndIdDic] valueForKey:#"items"]objectAtIndex:0];
NSURL *imgurl =[NSURL URLWithString:[[Dic valueForKey:#"image"] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSArray *subviewsArr = [self.view subviews];
for (int i=0; i<[subviewsArr count]; i++) {
if ([[subviewsArr objectAtIndex:i] isKindOfClass:[ImageDownLoader class]]) {
}
}
[self loadScrollView];
}
-(void)SetValuesInUserInterface:(NSDictionary *)Dic
{
self._imageView1.layer.cornerRadius = 4;
self._imageView1.clipsToBounds = YES;
self._imageView1.tag = 999;
NSURL *imgurl =[NSURL URLWithString:[[Dic valueForKey:#"image"] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
self._imageView1.image=[UIImage imageWithData:[NSData dataWithContentsOfURL:imgurl]];
NSArray *subviewsArr = [self.view subviews];
for (int i=0; i<[subviewsArr count]; i++) {
if ([[subviewsArr objectAtIndex:i] isKindOfClass:[ImageDownLoader class]]) {
[[subviewsArr objectAtIndex:i] removeFromSuperview];
}
}
if ([[Dic valueForKey:#"image"] isEqual:#""])
{
_imageView1.hidden=YES;
_txtView.frame=CGRectMake(4.0f,95.0f,_txtView.frame.size.width,_txtView.frame.size.height );
NSLog(#"NO IMAGE");
}
else{
_imageView1.hidden=NO;
_imageView1.frame=CGRectMake(4.0f,95.0f,310.0f,180.0f );
// _txtView.frame=CGRectMake(4.0f,316.0f,310.0f,159.0f );
_txtView.frame=CGRectMake(4.0f,316.0f,_txtView.frame.size.width,_txtView.frame.size.height );
NSLog(#"IMAGE VISIBLE");
}
self._scrollView.scrollEnabled = YES;
self._scrollView.showsVerticalScrollIndicator = YES;
self._scrollView.showsHorizontalScrollIndicator = YES;
self._header.font = [UIFont fontWithName:#"HelveticaNeue-MediumCond" size:18];
[self._header setText: [Dic valueForKey:#"header"]];
self._header.textColor=[UIColor blackColor];
[self._Writer setText:[Dic valueForKey:#"AUTHOR"]];
[self._kicker setText:[Dic valueForKey:#"kicker"]];
[self._txtView setText:[Dic valueForKey:#"ARTICLE_BODY"]];
NSString *writer;
if ([[Dic valueForKey:#"AUTHOR"] length]>2)
{
writer=[NSString stringWithFormat:#"%#, ",[Dic valueForKey:#"AUTHOR"]];
}
else
{
writer=#"";
}
[self._Writer setText:str];
[_txtView sizeToFit]; //added
[_txtView layoutIfNeeded]; //added
CGRect frame = self._txtView.frame;
self._txtView.frame = frame;
[_txtView setScrollEnabled:NO];
self._scrollView.contentSize = CGSizeMake(320,440+frame.size.height);
_titleLabel.frame= CGRectMake(0, self._scrollView.contentSize.height-119, [[UIScreen mainScreen] bounds].size.width, 40);
_titleLabel.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:1];
_titleLabel.textColor = [UIColor whiteColor];
_titleLabel.textAlignment = NSTextAlignmentCenter;
_titleLabel.font = [UIFont fontWithName:#"Helvetica" size:13.5];
_titleLabel.numberOfLines=2;
[self._scrollView addSubview:_titleLabel];
[self loadScrollView];
}
-(void)viewWillAppear:(BOOL)animated
{
self.navigationController.navigationBarHidden = YES;
}
- (void)viewDidLoad
{
[self DownLoadData:resultDic];
UISwipeGestureRecognizer *rightRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(loadScrollView)];
rightRecognizer.direction = UISwipeGestureRecognizerDirectionRight;
[rightRecognizer setNumberOfTouchesRequired:1];
//add the your gestureRecognizer , where to detect the touch..
[_scrollView addGestureRecognizer:rightRecognizer];
UISwipeGestureRecognizer *leftRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(loadScrollView)];
leftRecognizer.direction = UISwipeGestureRecognizerDirectionLeft;
[leftRecognizer setNumberOfTouchesRequired:1];
[_scrollView addGestureRecognizer:leftRecognizer];
}
- (void)rightSwipeHandle:(UISwipeGestureRecognizer*)gestureRecognizer
{
[self btnPreviousClick];
[self loadScrollView];
}
- (void)leftSwipeHandle:(UISwipeGestureRecognizer*)gestureRecognizer
{
NSLog(#"leftSwipeHandle");
[self btnNextClick];
[self loadScrollView];
}
-(IBAction)btnNextClick
{
btnPreviousNews.userInteractionEnabled=TRUE;
if(count!=[_arrUrlLinks count] -1)
{
if(count==[_arrUrlLinks count]-2)
{
btnNextNews.userInteractionEnabled=FALSE;
[btnNextNews setImage:[UIImage imageNamed:#"arrow2_next.png"] forState:UIControlStateNormal];
}
[btnPreviousNews setImage:[UIImage imageNamed:#"arrow1_prev.png"] forState:UIControlStateNormal];
count=count +1;
_lblNewsCount.text=[NSString stringWithFormat:#"%d/%d",count+1,[_arrUrlLinks count]];
NSLog(#"next %d",count);
[self performSelectorInBackground:#selector(DownLoadData:) withObject:[NSString stringWithFormat:#"%d",count]];
}
else{
btnNextNews.userInteractionEnabled=FALSE;
}
}
-(void)btnPreviousClick
{
btnNextNews.userInteractionEnabled=TRUE;
if(count==0)
{
btnPreviousNews.userInteractionEnabled=FALSE;
}
else{
if(count==1)
{
[btnPreviousNews setImage:[UIImage imageNamed:#"arrow2_prev.png"] forState:UIControlStateNormal];
btnPreviousNews.userInteractionEnabled=FALSE;
}
[btnNextNews setImage:[UIImage imageNamed:#"arrow1_next.png"] forState:UIControlStateNormal];
count=count-1;
_lblNewsCount.text=[NSString stringWithFormat:#"%d/%d",count+1,[_arrUrlLinks count]];
NSLog(#"previous %d",count);
[self performSelectorInBackground:#selector(DownLoadData:) withObject:[NSString stringWithFormat:#"%d",count]];
}
}
-(void)loadScrollView
{
_scrollView.contentSize = CGSizeMake(0, _scrollView.frame.size.height);
NSMutableArray *controllers = [[NSMutableArray alloc] init];
for (unsigned i = 0; i < [_arrUrlLinks count]; i++) {
[controllers addObject:[NSNull null]];
}
self.viewControllers = controllers;
count=1;
// a page is the width of the scroll view
_scrollView.pagingEnabled = YES;
_scrollView.contentSize = CGSizeMake(_scrollView.frame.size.width * [_arrUrlLinks count], _scrollView.frame.size.height);
_scrollView.showsHorizontalScrollIndicator =YES;
_scrollView.showsVerticalScrollIndicator = NO;
_scrollView.scrollsToTop = NO;
_scrollView.delegate = self;
pageControl.numberOfPages = [_arrUrlLinks count];
pageControl.currentPage = 0;
[_scrollView addSubview:_txtView];
[_txtView setText:[Dic valueForKey:#"ARTICLE_BODY"]];
[controller.view addSubview:_txtView];
// pages are created on demand
// load the visible page
// load the page on either side to avoid flashes when the user starts scrolling
[self loadScrollViewWithPage:0];
[self loadScrollViewWithPage:1];
}
- (void)loadScrollViewWithPage:(int)page {
if (page < 0) return;
if (page >= [_arrUrlLinks count])
return;
// replace the placeholder if necessary
controller = [viewControllers objectAtIndex:page];
if ((NSNull *)controller == [NSNull null]) {
NSString *deviceType = [UIDevice currentDevice].model;
if([deviceType isEqualToString:#"iPhone"])
{
controller = [[MyViewController alloc] initWithNibName:#"MyViewController" bundle:nil];
}
else{
controller = [[MyViewController alloc] initWithNibName:#"MyViewController_ipad" bundle:nil];
}
[controller initWithPageNumber:page];
// [controller.view addSubview:_txtView];
// [controller.view addSubview:_imageview];
NSLog(#"loadscrollviewwithpage");
[viewControllers replaceObjectAtIndex:page withObject:controller];
// [controller release];
}
// add the controller's view to the scroll view
if (nil == controller.view.superview) {
CGRect frame = _scrollView.frame;
frame.origin.x = frame.size.width * page;
frame.origin.y = 0;
controller.view.frame = frame;
// _txtView.frame=frame;
// _imageview.frame=frame;
// _txtView.frame=CGRectMake(4.0f,316.0f,310.0f,159.0f );
_txtView=#"hello";
// [controller.view addSubview:_txtView];
[_imageView1 addSubview:controller.view];
// [_txtView addSubview:controller.view];
// [scrollView addSubview:controller.view];
NSLog(#"loadscrollviewwithpage................>>>>>>>>>>>>");
// [self._header setText: [Dic valueForKey:#"header"]];
// [self DownLoadData:resultDic];
//[self SetValuesInUserInterface:Dic];
[self DownloadNext:resultDic];
}
}
- (void)unloadScrollViewWithPage:(int)page {
if (page < 0) return;
if (page >= [_arrUrlLinks count]) return;
controller = [viewControllers objectAtIndex:page];
if ((NSNull *)controller != [NSNull null]) {
if (nil != controller.view.superview)
[controller.view removeFromSuperview];
[viewControllers replaceObjectAtIndex:page withObject:[NSNull null]];
// [controller.view addSubview:_txtView];
// [controller.view addSubview:_imageview];
NSLog(#"Unloadscrollviewwithpage");
// [[NSURLCache sharedURLCache] removeAllCachedResponses];
}
}
- (void)scrollViewDidScroll:(UIScrollView *)sender {
// We don't want a "feedback loop" between the UIPageControl and the scroll delegate in
// which a scroll event generated from the user hitting the page control triggers updates from
// the delegate method. We use a boolean to disable the delegate logic when the page control is used.
if (pageControlUsed) {
// do nothing - the scroll was initiated from the page control, not the user dragging
return;
}
// Switch the indicator when more than 50% of the previous/next page is visible
CGFloat pageWidth = _scrollView.frame.size.width;
int page = floor((_scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
pageControl.currentPage = page;
// NSLog(#"current page %d",page);
// load the visible page and the page on either side of it (to avoid flashes when the user starts scrolling)
[self unloadScrollViewWithPage:page - 2];
[self loadScrollViewWithPage:page - 1];
[self loadScrollViewWithPage:page];
[self loadScrollViewWithPage:page + 1];
[self unloadScrollViewWithPage:page + 2];
count=page+1;
// [self newCountTitleSet];
// A possible optimization would be to unload the views+controllers which are no longer visible
}
// At the begin of scroll dragging, reset the boolean used when scrolls originate from the UIPageControl
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollViewLoc
{
CGFloat pageWidth = scrollViewLoc.frame.size.width;
CGPoint translation = [scrollViewLoc.panGestureRecognizer translationInView:scrollViewLoc.superview];
int page = floor((scrollViewLoc.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
if(translation.x > 0)
{
if(_strCurrentNewsSelect!=0)
{
if(page==0)
{
NSLog(#"OK");
NSLog(#"scrollviewwillbegindragging=0");
[self DownLoadDataPrevious:[_strCurrentNewsSelect.integervalue]-1];
}
}
else{
if(page==1)
{
NSLog(#"previous button");
[self btnPreviousClick];
}
}
} else
{
// [_txtView setText:[Dic valueForKey:#"ARTICLE_BODY"]];
// [controller.view addSubview:_txtView];
// [controller.view addSubview:_txtView];
// [controller.view addSubview:_imageview];
NSLog(#"loadscrollviewwithpage else");
[self btnPreviousClick];
NSLog(#"previous news");
// if(galleryItemClick+1!=[arrGallaeryUrl count])
//
// {
//
if(page+1==[_arrUrlLinks count])
//
{
//
NSLog(#"====....>>>>>>>");
}
count=count+1;
}
}
By using this code I am able to create the view controllers according to my array count[_arrUrlLinks] but the contents are not loaded on these views. On my first view I can only see an image view in black color rest of the views are blank.
How can I get the contents loaded on these views?

Resources