This will be a simple tutorial showing you how to put a UITextField in a UIAlertView. This is simple and just a couple lines if code. You will learn CGAffineTransform and coding UITextField programmatically.
Heres a screenshots of what we should get.
So lets go ahead and get started… 1. Create A New View Based Application You can name it whatever you want, I am gonna name it TextFieldInAlert. 2. Implementing The Code
Jump in the viewcontroller.m or if you called it TextFieldInAlert then TextFieldInAlert.m Now find the -(void)viewDidLoad method. Uncomment it and put this code in there.
- (void)viewDidLoad {
[superviewDidLoad];
UIAlertView *alert = [[UIAlertViewalloc] initWithTitle:@”Enter Name Here”message:@”this gets covered!”
So we are basically calling a UIAlertView and then we are adding the UITextField programmatically. You might have noticed in the message part of the UIAlertView we put “this gets covered!”, if we didn’t put that sentence then the alerts buttons would go up more and the UITextField will be messed. You can try taking that line out and see what happens. Now Build and Run the app. Now you got the UITextField to be inside the UIAlertView. Now try tapping the UITextField. Uh oh, why is the Keyboard covering the UIAlertView? Well there is just a simple fix to this. We just add two more lines of code and it will fix that. Add this to your code
Now if you Build and Run, you will notice the UITextField is a little higher and when you tap the UITextField the Keyboard doesn’t cover it up anymore. That is what the CGAffineTransform was for. So that is basically it! There is a video tutorial also available and if you like video tutorial more then written ones you can check it out out by clicking HERE. You can download the source code below. Happy iCoding! iPhone Tutorial – UITextField In A UIAlertView
I'm currently working on the chapter for More iPhone 3 Development on accessing the iPod Library. I thought I'd throw out another bit of teaser code in the form of a category. MPMediaItemCollection is the class that is used to specify queues of songs to be played. Unfortunately, it's an immutable collection object, and there is no mutable counterpart to it. That makes it kind of a pain when you have to add, delete, or insert items into a collection, or when you want to join multiple collections together.
This category adds a bunch of methods to MPMediaItemCollection that make it easier to manipulate play queues. It doesn't make MPMediaItemCollection mutable, but it does the next best thing. It makes it easier to create new collections based on existing collections. There are methods that create new collections by inserting or deleting songs from an existing collection.
I plan to add a few additional methods for sorting and re-ordering collections for the final version of this category, so look for an update to this in the next few days.
Note: I fixed a couple of leaks after the initial posting
MPMediaItemCollection-Utils.h
#import <Foundation/Foundation.h>
#import <MediaPlayer/MediaPlayer.h>
@interface MPMediaItemCollection(Utils)
/** Returns the first media item in the collection
**/
- (MPMediaItem *)firstMediaItem;
/** Returns the last media item in the collection
**/
- (MPMediaItem *)lastMediaItem;
/** This method will return the item in this media collection at a specific index
**/
- (MPMediaItem *)mediaItemAtIndex:(NSUInteger)index;
/** Given a particular media item, this method will return the next media item in the collection.
If there are multiple copies of the same media item in the list, it will return the one
after the first occurrence.
**/
- (MPMediaItem *)mediaItemAfterItem:(MPMediaItem *)compare;
/** Returns the title of the media item at a given index.
**/
- (NSString *)titleForMediaItemAtIndex:(NSUInteger)index;
/** Returns YES if the given media item occurs at least once in this collection
**/
- (BOOL)containsItem:(MPMediaItem *)compare;
/** Creates a new collection by appending otherCollection to the end of this collection
**/
- (MPMediaItemCollection *)collectionByAppendingCollection:(MPMediaItemCollection *)otherCollection;
/** Creates a new collection by appending an array of media items to the end of this collection
**/
- (MPMediaItemCollection *)collectionByAppendingMediaItems:(NSArray *)items;
/** Creates a new collection by appending a single media item to the end of this collection
**/
- (MPMediaItemCollection *)collectionByAppendingMediaItem:(MPMediaItem *)item;
/** Creates a new collection based on this collection, but excluding the specified items.
**/
- (MPMediaItemCollection *)collectionByDeletingMediaItems:(NSArray *)itemsToRemove;
/** Creates a new collection based on this collection, but which doesn't include the specified media item.
**/
- (MPMediaItemCollection *)collectionByDeletingMediaItem:(MPMediaItem *)itemToRemove;
/** Creates a new collection based on this collection, but excluding the media item at the specified index
**/
- (MPMediaItemCollection *)collectionByDeletingMediaItemAtIndex:(NSUInteger)index;
/** Creates a new collection, based on this collection, but excluding the media items starting with
(and including) the objects at index from and ending with (and including) to.
**/
- (MPMediaItemCollection *)collectionByDeletingMediaItemsFromIndex:(NSUInteger)from toIndex:(NSUInteger)to;
@end