IOS UINavigationController use


1 appdelegate.h

  定义属性: window,navigationViewController

@interface AppDelegate : UIResponder <UIApplicationDelegate>


@property (strong, nonatomic) UIWindow *window;


@property (strong, nonatomic) UINavigationController *navigationViewController;


@end 

 

2 appdelegate.m

对属性初始化,窗口初始化


@implementation AppDelegate

@synthesize window=_window;

@synthesize navigationViewController=_navigationViewController;


- (void)dealloc

{

    [_window release];

    [_navigationViewController release];

    [super dealloc];

}


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

{

    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];

    // Override point for customization after application launch.

    

    RootViewController* rootViewController=[[[RootViewController alloc] initWithNibName:@"RootViewController" bundle:nil] autorelease];

    

    self.navigationViewController=[[[UINavigationController alloc] initWithRootViewController:rootViewController] autorelease];

 

    self.window.rootViewController = self.navigationViewController;

    [self.window makeKeyAndVisible];

    return YES;

} 

 

RootViewController.h 初始化加载数据到tabveiwController

- (void)viewDidLoad

{

    [super viewDidLoad];


    // Uncomment the following line to preserve selection between presentations.

    // self.clearsSelectionOnViewWillAppear = NO;

 

    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.

    // self.navigationItem.rightBarButtonItem = self.editButtonItem;

    self.categary=[NSArray arrayWithObjects:@"11",@"22",@"33",@"44", nil];

    self.title=@"sina wei bo";

}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

{

    // Return the number of sections.

    return 1;

}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

    // Return the number of rows in the section.

    return [self.categary count];

}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    

    // Configure the cell...

    if (cell==nil) {

        cell=[[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];

    }

    cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;

    cell.textLabel.text=[self.categary objectAtIndex:indexPath.row];

    cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;

    return cell;

}

 

点击一个CELL,跳转到下一窗口

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{

    // Navigation logic may go here. Create and push another view controller.

    /*

     <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];

     // ...

     // Pass the selected object to the new view controller.

     [self.navigationController pushViewController:detailViewController animated:YES];

     [detailViewController release];

     */

    SubViewController *subViewController=[[SubViewController alloc] initWithNibName:@"SubViewController" bundle:nil];

    

    [self.navigationController pushViewController:subViewController animated:YES];

    [SubViewController release];

}

 

posted @   大树2  阅读(1541)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!
点击右上角即可分享
微信分享提示