Xcode 4.2 缺省创建的Tabbed Application是这个样子的。
而且类被命名为XXFirstViewController,XXXSecondViewController,让我们很不爽,很多时候,我们需要更有意义的类名,更多的tab选项。那么我下面给大家演示以下如何自己定义这些。
我们假如创建一个有三个选项的工程,并且三个相关的viewcontroller分别是普通的,table View,带table view的导航模式的,并且命名为FViewController, SViewController,TViewController。
选择新建一个Tab bar Application,并把工程名称命名为tTabApp。
建好后的工程目录如下:
删除上面的tcFirstViewController.h,tcFirstViewController.m,tcSecondeViewController.h,tcSecondViewController.m,tcFirstViewController.xib,tcSecondViewController.xib六个文件。
在tTabApp上点击右键,加入FViewController.
选择UIViewController subclass
输入类名为FViewController,并且下面一定要选择Subclass of : UIViewController.
还需要选中With XIB for user interface.
然后依此假如另外两个View Controller,注意后面的两个必须在最后一个界面上的Subclass of :UITableViewController
这时候的工程目录如下:
在FViewController.m中修改一个函数
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super
initWithNibName:nibNameOrNil
bundle:nibBundleOrNil];
if (self) {
// Custom initialization
//self.title = @"第一个";
self.tabBarItem.title =@"第一个";
self.tabBarItem.image = [UIImage
imageNamed:@"first"];
}
returnself;
}
修改SViewController中几个函数如下:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super
initWithNibName:nibNameOrNil
bundle:nibBundleOrNil];
if (self) {
// Custom initialization
self.tabBarItem.title =@"第二个";
self.tabBarItem.image = [UIImage
imageNamed:@"second"];
}
returnself;
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
#warning Potentially incomplete method implementation.
删除上面的一样,这行永远会在编译期间生成一个警告
// Return the number of sections.
return 1;
上面一行0改为1
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
#warning Incomplete method implementation.
// Return the number of rows in the section.
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static
NSString *CellIdentifier =
@"Cell";
UITableViewCell *cell = [tableViewdequeueReusableCellWithIdentifier:CellIdentifier];
if (cell ==
nil) {
cell = [[[UITableViewCellalloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:CellIdentifier]autorelease];
}
cell.textLabel.text =@"1111";
上面这行是加入的,
// Configure the cell...
return cell;
}
在TViewController中做同样的更改,并且注意cell.textLabel.text=@"1111";改为cell.textLabel.text=@"222222";。以示区分。
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super
initWithNibName:nibNameOrNil
bundle:nibBundleOrNil];
if (self) {
// Custom initialization
self.title =
@"第三个";
self.tabBarItem.image = [UIImage
imageNamed:@"second"];
}
returnself;
}
在tcAppDelegate.m文件中加入import如下:
#import"FViewController.h"
#import"SViewController.h"
#import"TViewController.h"
在tcAppDelegate.m文件中修改函数
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
如下:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindowalloc]initWithFrame:[[UIScreenmainScreen]bounds]]autorelease];
// Override point for customization after application launch.
UIViewController *viewController1 = [[FViewControlleralloc]initWithNibName:@"FViewController"bundle:nil];
UIViewController *viewController2 = [[SViewControlleralloc]initWithNibName:@"SViewController"bundle:nil];
UIViewController *viewController3 = [[TViewControlleralloc]initWithNibName:@"TViewController"bundle:nil];
UINavigationController *navigationController = [[UINavigationControlleralloc]initWithRootViewController:viewController3];
self.tabBarController = [[[UITabBarControlleralloc]init]autorelease];
self.tabBarController.viewControllers = [NSArrayarrayWithObjects:viewController1,
viewController2, navigationController,nil];
[viewController1
release];
[viewController2release];
[viewController3release];
[navigationControllerrelease];
self.window.rootViewController =self.tabBarController;
[self.windowmakeKeyAndVisible];
returnYES;
}
最后形成的效果是。
分享到:
相关推荐
xcode 4.2 and iOS5 sdk torrent 文件
xcode4.2 ios5sdk snowleopard
XCode4.2中使用Empty Application模板替代旧的Window Based
xcode 4.2 免证书真机调试配置 1、根据《XCode 4.2 免证书调试之...6、XCode4.2项目中,Build Setting->Code signing->Code signing Identity, 点击"Don't Code Sign",选择other,在弹出框中填入"iPhone Developer"。
Snow Leopard 上最后一个版本的xcode 网络上已经没有其他可下载的资源点 xcode_4.2_and_ios_5_sdk_for_snow_leopard.dmg xcode_4.2_and_ios_5_sdk_for_lion.dmg md5:4e0efebe696d31b46ab4b117015515a5
OpenGL ES 从零开始系列教程的工程模板,XCode4.2,路径为/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates/Project Templates/Application/
Xcode4.2教程(斯坦福大学iOS开发教程3_Walkthrough iOS 5.pdf) 适用于4.2以上版本的Xcode
最新XCODE4.2英文书籍,有XCODE4的使用教程。
呵呵,不用多解释,有需要的自己下吧,这个是种子,用什么下载?当然迅雷啦
xcode 4.2 and IOS 5.0 DP
从零开始学习OpenGL ES系列教程的工程模板,XCode4.2,路径为/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates/Project Templates/Application/
snow xcode 4.2 mac,亲测,速度不错
XCode 4.2 & iOS5 SDK
iOS5开发基础教程 最新版本 xcode4.2,让你不再为新老版本界面而烦恼,目前只能找到英文版本了。
Xcode 4.1/4.2/4.2.1 免证书(iDP)开发+真机调试+生成IPA全攻略
XCODE4.2写的计算器,只有加减乘除,有优先级,可以计算表达式的值
Apple Xcode 4.2 下载地址(非官方)
利用这个torrent文件,使用迅雷进行下载xcode_4.2_and_ios_5_sdk_for_snow_leopard.dmg , 在虚拟机的苹果电脑中进行安装xcode
虚拟机搭建苹果开发环境工具集。 vmware8&keymaker电驴下载 OSX10.7 Lion种子文件 xcode4.2 for lion 种子文件 HJMace引导光盘 Darwin3.1 Vmtools驱动。
Mac下面xcode4.2和iossdk的安装