Jun 13

I don’t know if it has ever happend to you that to clean your iPhone Simulator instead of deleting app by app, you did a reset and found out that all pictures had dissapeared XD, what did you expect ;).

Well, if you did a reset willingly, by error or to clean all the apps and data that is created while you test and test your apps, here there are a couple of tricks to add new pictures:

Photos we have on files:

To add pictures from your own files you only have to copy them into:

~/Users/<usuario>/Library/Application Support/iPhone Simulator/3.1.3/Media/DCIM/100APPLE

Where <usuario> is your user name, and maybe you have to change too the SDK version you are working with.

Note: I have seen different routes around internet, the idea is that you have to be in the iPhone Simulator folder ~/Library/Application Support/iPhone Simulator/… and add the images to Media/DCIM/100APPLE, i this last folder doesn’t exist you must create it.

Variant: You can also open Safari in your simulator and drag file by file to the webpage, then hold left click on the image till you  get the option to save it. It will be added to your library.

Pictures from internet:

In case you want to add new images from internet, for example google images, you only need to do as before, click and hold on the image you want to safe in Safari to get the option to save it.

VN:F [1.9.8_1114]
Rating: 0.0/5 (0 votes cast)
VN:F [1.9.8_1114]
Rating: 0 (from 0 votes)
Tagged with:
Jun 09

Sorry, this entry is only available in Español.

VN:F [1.9.8_1114]
Rating: 5.0/5 (1 vote cast)
VN:F [1.9.8_1114]
Rating: 0 (from 0 votes)
Tagged with:
Jun 09

VN:F [1.9.8_1114]
Rating: 0.0/5 (0 votes cast)
VN:F [1.9.8_1114]
Rating: +1 (from 1 vote)
Tagged with:
Jun 09

Sorry, this entry is only available in Español.

VN:F [1.9.8_1114]
Rating: 5.0/5 (2 votes cast)
VN:F [1.9.8_1114]
Rating: +1 (from 3 votes)
Tagged with:
Jun 07

Sorry, this entry is only available in Español.

VN:F [1.9.8_1114]
Rating: 0.0/5 (0 votes cast)
VN:F [1.9.8_1114]
Rating: 0 (from 0 votes)
Tagged with:
Jun 05

VN:F [1.9.8_1114]
Rating: 0.0/5 (0 votes cast)
VN:F [1.9.8_1114]
Rating: 0 (from 0 votes)
Tagged with:
Jun 05

When we want to create an application that contains different functionality related with the use of the application, but independent between them, like showing data in different ways or different tasks, we will want to use a Tab Bar in our application.

The Tab Bar will gave us acces to this different views, like independent modules, more over, it helps the user to place himself inside the application, telling him what he is seeing.

Today we will give basic indication to create and set up a Tab Bar in our application. In Xcode we have a template which will create an application with a Tab Bar and two different views, although it is a good start point, when we take a look to the code we can see much of what it’s going on, that because they use Interface Builder to do almost all the setting up. We will show a bit more of code.

Structure

We have an application, inside there is our Tab Bar, we need to tell the Tab Bar which views (UIViewController) it has to show, each view will take care of itself, but we need to setup the property tabBarItem (UITabBarItem) for each view so the Tab Bar can show us the icon and title of it.

Data

The only thing we need is an icon for each view and a title. We can use both at the same time or only one of them, of course, a Tab Bar only with a title doesn’t look right so I will recommend at least to use an icon to represent what is done in that tab. The title is always welcome when the icon is not clear what represents.

The title isn’t more than a normal string that we will give in the code, but the icon is a bit more tricky and although Apple give as some system icons to use, take a look at UITabBarSystemItem, they also tell us how we have to create our own icon.

▪ Use PNG format.
▪ Use only pure white with proper transparency.
▪ Don’t add shadows.
▪ Use anti-aliasing.
▪ Size of 30 x 30 pixels.

Code

To create the Tab Bar and add it to the application use this

- (void)applicationDidFinishLaunching:(UIApplication *)application {
 
tabBarController = [[UITabBarController alloc] init];
 
MyViewController* vc1 = [[MyViewController alloc] init];
 
MyOtherViewController* vc2 = [[MyOtherViewController alloc] init];
 
NSArray* controllers = [NSArray arrayWithObjects:vc1, vc2, nil];
 
tabBarController.viewControllers = controllers;
 
[window addSubview:tabBarController.view];
 
}

We create the Tab Bar, the view controllers we need and put those in an array to tell the Tab Bar those are the one it has to show. We add the Tab Bar view to the window and we are finished.

To set up each of the UITabBarItem of each view we can use the following lines

UIImage* anImage = [UIImage imageNamed:@"MyTabBarIcon.png"];
 
UITabBarItem* theItem = [[UITabBarItem alloc] initWithTitle:@"TabBarItemTitle" 
                                                     image:anImage tag:0];
 
[myViewController setTabBarItem:theItem];

Usually we will put these lines in the view controller itself, on the init method, but might be necesarly to do it in some other place when we are not using our own classes, for example when one of the tabs uses a Navigation Bar, in that case we can put these lines just after creating the Navigation Bar.

VN:F [1.9.8_1114]
Rating: 5.0/5 (1 vote cast)
VN:F [1.9.8_1114]
Rating: -1 (from 1 vote)
Tagged with:
May 29

This week, in an earlier post, we were showing how to use the common flip animation to show a view with the credits of the application. Today we are going to do the same but using the modal views that are implemented in the class UIViewController.

What we did show is usefull when we want to fully control the animation, but this other way will save us a lot of code and if we don’t want to do anything special during the animation will be enought.

We start the same way, with a table view inside a navigation bar, we add the information button to our controller.

- (void)viewDidLoad {
    [super viewDidLoad];
 
    self.title = @"Main menu";
 
    UIButton* infoButton = [UIButton buttonWithType:UIButtonTypeInfoLight];
    [infoButton addTarget:self action:@selector(showAbout:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:infoButton];
}

but in this case, our showAbout will be more simple

-(void)showAbout:(id)sender{
	AboutController *a = [[AboutController alloc] init];
	UINavigationController *n = [[UINavigationController alloc] initWithRootViewController:a] ;
	[a release];
 
	[a setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
	[self presentModalViewController:n animated:YES];
}

We are still creating a navigation bar and our credits view, but this time we indicate to our about view how we want the modal animation to be with the sentence [a setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal]; and finally we tell the controller of the actual view to present the new navigation bar.

Here there is a point that can be a little confussing, we are telling one controller how should be the animation, but we present another controller, in fact, if instead of [a setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal]; we use [n setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal]; with the navigation bar controller n, we get the same result, this is becouse the about view is the root view for the navigation bar. But, we can’t do the same in the last sentence or we won’t see the navigation bar that allows us to go back.

Now in the .m of the About controller we leave the viewDidLoad untouched, adding the “Ok” button that once pressed will take us back to our main controller.

- (void)viewDidLoad {
    [super viewDidLoad];
    UIBarButtonItem *btn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemDone target:self action:@selector(close:)];
    self.navigationItem.rightBarButtonItem = btn;
    [btn release];
}
 
but our close will be only one line of code, the one that makes the modal view to go away.
 
-(void)close:(id)sender{
       [self dismissModalViewControllerAnimated:YES];
}

Realice that this way we don’t need anymore to keep truck of the main controller to be able to go back to it, this is becouse using modal views we still have it in the view hierarchy.

VN:F [1.9.8_1114]
Rating: 5.0/5 (1 vote cast)
VN:F [1.9.8_1114]
Rating: +1 (from 1 vote)
Tagged with:
May 23

VN:F [1.9.8_1114]
Rating: 5.0/5 (5 votes cast)
VN:F [1.9.8_1114]
Rating: +1 (from 1 vote)
Tagged with:
May 23

VN:F [1.9.8_1114]
Rating: 5.0/5 (1 vote cast)
VN:F [1.9.8_1114]
Rating: +1 (from 1 vote)
Tagged with:
preload preload preload