Navigation Controller inside a Tab Bar Controller
When you are using a Tab View controller based project it doesn’t come with a navigation stack by default. So if you would like have a navigation view on each tab, with a tab bar and back button, when navigating in the stack, here is the code to do so. All you need to do is modify the function: didFinishLaunchingWithOptions.
Standard Code
This is the standard code that you get when you create a tab view project:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
UIViewController *viewController1, *viewController2, *viewController3;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
viewController1 = [[[MainViewController alloc] initWithNibName:@”MainViewController_iPhone” bundle:nil] autorelease];
viewController2 = [[[SecondViewController alloc] initWithNibName:@”SecondViewController_iPhone” bundle:nil] autorelease];
viewController3 = [[[SettingsViewController alloc] initWithNibName:@”SettingsViewController_iPhone” bundle:nil] autorelease];
} else {
viewController1 = [[[MainViewController alloc] initWithNibName:@”MainViewController_iPad” bundle:nil] autorelease];
viewController2 = [[[SecondViewController alloc] initWithNibName:@”SecondViewController_iPad” bundle:nil] autorelease];
viewController3 = [[[SettingsViewController alloc] initWithNibName:@”SettingsViewController_iPad” bundle:nil] autorelease];
}
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.viewControllers = @[viewController1, viewController2, viewController3];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
Modified Function to add a Navigation Stack
All you simply need to do is embed the main view controllers for each tab inside a navigation view controller.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
UINavigationController *navController1, *navController2, *navController3;
UIViewController *viewController1, *viewController2, *viewController3;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
viewController1 = [[[MainViewController alloc] initWithNibName:@”MainViewController_iPhone” bundle:nil] autorelease];
viewController2 = [[[SecondViewController alloc] initWithNibName:@”SecondViewController_iPhone” bundle:nil] autorelease];
viewController3 = [[[SettingsViewController alloc] initWithNibName:@”SettingsViewController_iPhone” bundle:nil] autorelease];
} else {
viewController1 = [[[MainViewController alloc] initWithNibName:@”MainViewController_iPad” bundle:nil] autorelease];
viewController2 = [[[SecondViewController alloc] initWithNibName:@”SecondViewController_iPad” bundle:nil] autorelease];
viewController3 = [[[SettingsViewController alloc] initWithNibName:@”SettingsViewController_iPad” bundle:nil] autorelease];
}
navController1 = [[[UINavigationController alloc] initWithRootViewController:viewController1] autorelease];
navController2 = [[[UINavigationController alloc] initWithRootViewController:viewController2] autorelease];
navController3 = [[[UINavigationController alloc] initWithRootViewController:viewController3] autorelease];
// navigation bar color
navController1.navigationBar.tintColor = [UIColor blackColor];
navController2.navigationBar.tintColor = [UIColor blackColor];
navController3.navigationBar.tintColor = [UIColor blackColor];
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.viewControllers = @[navController1, navController2, navController3];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
Any problems, please feel free to send me an email.
How to do a CSS Drop Shadow, you a web page.
Here is a page explaining how to create a drop shadow:
Creating a File System on an external drive.
mkfs.ext3 -j /dev/sdb1
Got sdb1 from fdisk -l or dmesg (from when the disk is enumerated)
(This probably wipes the disk)
Then you can mount it
mount -t ext3 /dev/sdb1 /mnt/usb-backup (make sure usb-backup exists)
I carried out the above when I was trying to mount an external hard disk and getting the following error:
mount: wrong fs type, bad option, bad superblock on ext3 partition….
Creating a Samba Folder
In the file:
$ sudo vi /etc/samba/smb.conf
Add the lines:
[folder-name]
comment = Shared reference data (will not be backed up)
path = /home/john/sambafolder
writeable = yes
browseable = yes
valid users = john
$ sudo service smbd restart
If a file exists in Perl
#!/usr/bin/perl -w $filename = '/path/to/your/file.doc'; if (-e $filename) { print "File Exists!"; }
Also get the file size:
#!/usr/bin/perl -w $filename = '/path/to/your/file.doc'; $filesize = -s $filename; print $filesize;
Samba file share with a Windows Server
You may need to install smbfs:
sudo apt-get install smbfs
I assume samba is already installed, if not:
sudo apt-get install samba
Create directory to mount
$mkdir -p /mnt/win
Mount windows server to the newly created directory$mount -t smbfs -o username=winntuser,password=mypassword //windowsserver/sharename /mnt/win
(Source)
Next create the password file /etc/sambapasswords:cat > /etc/sambapasswords username = winntuserpassword = mypasswordmake sure that only root have access to itchown root:root /etc/sambapasswordschmod 600 /etc/sambapasswords
Add an entry to your /etc/fstab:
//windowserver/share /mnt/win smbfs
auto,gid=users,fmask=0664,dmask=0775,iocharset=iso8859-15, credentials=/etc/sambapasswords 0 0
Call Sudo from a Perl Script
use Sudo; my $password = '*****';my $su = Sudo->new( { sudo => '/usr/bin/su', username => "*****" , password => $password, program => "/tmp/test.sh" , program_args => '' } ); $result = $su->sudo_run();print "$result \n";if (exists($result->{error}) ){ &handle_error($result);}else{ printf "STDOUT: %s\n",$result->{stdout}; printf "STDERR: %s\n",$result->{stderr}; printf "return: %s\n",$result->{rc};}
Install a Perl Module
$sudo perl -MCPAN -e shell
cpan> install Sudo
cpan> exit
It will ask you for a username and password, enter something you can remember.
For the Sudo Module, which is the module I was trying to install:
http://search.cpan.org/~landman/Sudo/lib/Sudo.pm#NAME
Returning a value from Perl Script
Howto set-up a crontab file
To edit crontab:
$crontab -e
16 18 * * * /home/user/backup_script.pl > /home/user/backup_script.log
Use ‘>’ to output standard output to a log file.
See below for the sterling explaination I found (thank you to corenominal.org):
(Source: http://corenominal.org/howto-setup-a-crontab-file/)
Creating a crontab file
crontab -e
crontab -l
Crontab syntax
* * * * * command to be executed- - - - -| | | | || | | | +----- day of week (0 - 6) (Sunday=0)| | | +------- month (1 - 12)| | +--------- day of month (1 - 31)| +----------- hour (0 - 23)+------------- min (0 - 59)
Crontab examples
* * * * * #Runs every minute30 * * * * #Runs at 30 minutes past the hour45 6 * * * #Runs at 6:45 am every day45 18 * * * #Runs at 6:45 pm every day00 1 * * 0 #Runs at 1:00 am every Sunday00 1 * * 7 #Runs at 1:00 am every Sunday00 1 * * Sun #Runs at 1:00 am every Sunday30 8 1 * * #Runs at 8:30 am on the first day of every month00 0-23/2 02 07 * #Runs every other hour on the 2nd of July
@reboot #Runs at boot@yearly #Runs once a year [0 0 1 1 *]@annually #Runs once a year [0 0 1 1 *]@monthly #Runs once a month [0 0 1 * *]@weekly #Runs once a week [0 0 * * 0]@daily #Runs once a day [0 0 * * *]@midnight #Runs once a day [0 0 * * *]@hourly #Runs once an hour [0 * * * *]
Multiple commands
&&” can be used to run multiple commands consecutively. The following example would run command_01 and then command_02 once a day:@daily &&
Disabling email notifications
>/dev/null 2>&1
Specifying a crontab file to use
crontab -e” command. However, you may already have a crontab file, if you do you can set it to be used with the following command:crontab -u
crontab -u tux ~/crontab
Removing a crontab file
crontab -r
Further information
man crontab
sudo: /etc/sudoers is mode 0640, should be 0440
sudo: no valid sudoers sources found, quitting
Or
You can use the live ubuntu CD, and mount the hard disk’s file system, then do the following:
$ chmod 0440 /etc/sudoers
Reboot normally
Working out disk usage on Linux
If you are running our of space on a linux box, then the following command will tell you 20 largest folders:
du -a /home | sort -n -r | head -n 20
A report of the overall disk space, for all the connected hard disks:
df
Very useful!
Blog Categories
Recent Posts
Recent Comments
- Steve on How to set the Navigation Bar Style.
- Clay on Good UISegmentedControl example
- Junior on Printf Formatting
- Kasey on Symbian Error Codes
- Dong on UITableView Separator colour


