Found this great article that shows how to scroll the view so that a textfield is in view when the keyboard appears.

http://de-co-de.blogspot.com/2009/03/moving-uitextfield-above-keyboard.html

I’ve copied the code below so that I have a reference to it as well.

You also need to ensure the following steps are followed…

  • Make your controller implement UITextViewDelegate
  • setup your textfield’s (s) delegate to be your controller
  • in the controller @interface add an int verticalOffset
  • in the controller @implementation add the functions below
  • #pragma mark "-- text editing support --"
    // Animate the entire view up or down, to prevent the keyboard from covering the text field.
    - (void)moveView:(int)offset {
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:0.3];
        // Make changes to the view's frame inside the animation block. They will be animated instead
        // of taking place immediately.
        CGRect rect = self.view.frame;
        rect.origin.y -= offset;
        rect.size.height += offset;
        self.view.frame = rect;
    
        [UIView commitAnimations];
    }
    
    - (BOOL)textFieldShouldReturn:(UITextField *) sender {
        [sender resignFirstResponder];
        if (verticalOffset!=0) {
            [self moveView: -verticalOffset];
            verticalOffset = 0;
        }
        return TRUE;
    }
    
    - (void)textFieldDidBeginEditing:(UITextField *)theTextField {
        int wantedOffset = theTextField.frame.origin.y-200;
        if ( wantedOffset < 0 ) {
            wantedOffset = 0;
        }
        if ( wantedOffset != verticalOffset ) {
            [self moveView: wantedOffset - verticalOffset];
            verticalOffset = wantedOffset;
        }
    }
    


Core Data – fetch a single entity

I’ve used the following code to retrieve an entity from Core Data, so that the result returns the entity object rather than a Dictionary

-(Target *) currentTargetInContext:(NSManagedObjectContext *)context {
	Target *match;

	NSFetchRequest *request = [[NSFetchRequest alloc] init];
	NSEntityDescription *entity = [NSEntityDescription entityForName: @"Target" inManagedObjectContext:context];
	[request setEntity:entity];

	[request setResultType:NSManagedObjectResultType];

	NSPredicate *predicate = [NSPredicate predicateWithFormat:@"Achieved == 0 "];
	[request setPredicate:predicate];

	NSError *error;
	NSArray *objects = [context executeFetchRequest:request error:&error];
	match = nil;
	if (objects == nil)
	{
		// handle the error
	}
	else
	{
		if ([objects count] > 0)
		{
			match = (Target *)[objects objectAtIndex:0];
		}
	}

	[request release];

	return match;
}


UIActionSheet in a tab view

I was getting problems displaying an action sheet in a view that was contained within a tab control.

UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"Are you sure you wish to continue?"
									   delegate:self
									  cancelButtonTitle:@"No"
								   destructiveButtonTitle:@"Yes"
									  otherButtonTitles:nil];
[sheet showInView:self.view];
[sheet release];

The prompt would be displayed but the clicking of the “No” button didn’t always work. The problem is although there is a view that can display the prompt, the correct view to do it is the tab bar, The following code works fine

UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"Are you sure you wish to continue?"
									   delegate:self
									  cancelButtonTitle:@"No"
								   destructiveButtonTitle:@"Yes"
									  otherButtonTitles:nil];
[sheet showFromTabBar:self.tabBarController.tabBar];
[sheet release];


CoreData – SQLite Manager for Firefox

This Firefox add-on allows you to view the data you are running against while using the iPhone simulator. Your sqlite files can be found in the following folder

/Users/”user name”/Library/Application Support/iPhone Simulator/User/Applications/”application guid”/Documents

SQLite Firefox add-on

This is a great tool for view the data you’ve created within your apps, but I would suggest that is best to define your data model via Xcode


In order to move the cursor automatically to the next data entry field when the user presses Next on the keyboard you need to resignFirstResponder from the current field and assign it to the next field using becomeFirstResponder

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
	if (textField == field1TextField) {
		[textField resignFirstResponder];
		[field2TextField becomeFirstResponder];
	}
	else if (textField == field2TextField) {
		[textField resignFirstResponder];
		[field3TextField becomeFirstResponder];
	}
	else if (textField == field3TextField) {
		[textField resignFirstResponder];
	}
	return YES;
}


You need to set the Return Key types accordingly within the interface builder


Provisioning 3.0.1 iPhones

If you’ve updated your development phones to have the latest OS, 3.0.1, then you won’t be able to load you apps onto the device without first following this apple advisory

2. Copy and paste the following line into Terminal:

ln -s /Developer/Platforms/iPhoneOS.platform/DeviceSupport/3.0\ \(7A341\) / Developer/Platforms/iPhoneOS.platform/DeviceSupport/3.0.1

But theres a catch, if you copy the text they have from the document into Terminal there is an extra space created before the second “Developer” path, remove that and all should be ok.

i.e. the command line should be…

ln -s /Developer/Platforms/iPhoneOS.platform/DeviceSupport/3.0\ \(7A341\) /Developer/Platforms/iPhoneOS.platform/DeviceSupport/3.0.1


Data Model change causes iPhone Simulator to fail

When you alter your underlying data model the iPhone simulator will not be able to load your app as the cached version of the database doesn’t match the new one. The easiest way to resolve the problem is to run the simulator, click and hold your app and remove it like you would remove an app from your actual phone.


iPhone Development starter book

If you want to get into iPhone development this is a great book to start from Beginning iPhone Development by apress


Next Entries