`
helmsman_xcode
  • 浏览: 25888 次
  • 来自: 北京
最近访客 更多访客>>
社区版块
存档分类
最新评论

UINavigationController,UIBarButtonItem应用的例子

 
阅读更多

rootViewController.m文件

- (void)viewDidLoad
{
    self.title = @"First Page"; 
    NSMutableArray *array = [[NSMutableArray alloc] init];
    DisclosureButtonController *buttonController = [[DisclosureButtonController alloc] initWithStyle:UITableViewStylePlain];
    buttonController.title = @"Button View";
    buttonController.image = [UIImage imageNamed:@"apple.png"];
    [array addObject:buttonController];
    
    self.listData = array;
    [array release];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"主页" style:UIBarButtonItemStyleBordered target:self action:@selector(leftButtonPressed)];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"下一页" style:UIBarButtonItemStyleBordered target:self action:@selector(rightButtonPressed)];
    [super viewDidLoad];
}

- (void)leftButtonPressed
{
    NSLog(@"Lefl Button");
}

- (void)rightButtonPressed
{
    NSLog(@"Right Button");
}
#pragma mark -
#pragma mark Table View Data Source Methods

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [self.listData count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *thekey = @"thekey";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:thekey];
    if(cell == nil){
        cell = [[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:thekey
                ];
    }
    NSUInteger row = [indexPath row];
    secondLevelViewController *nextController = [listData objectAtIndex:row];
    cell.textLabel.text = nextController.title;
    cell.imageView.image = nextController.image;
    return cell;
}

#pragma mark -
#pragma mark Table Delegate Methods

- (UITableViewCellAccessoryType)tableView:(UITableView *)tableView accessoryTypeForRowWithIndexPath:(NSIndexPath *)indexPath
{
    return UITableViewCellAccessoryDisclosureIndicator;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSUInteger row = [indexPath row];
    secondLevelViewController *nextController = [listData objectAtIndex:row];
    [self.navigationController pushViewController:nextController animated:YES];
}

 DisclosureDetailController.m文件

- (void)viewDidLoad
{
    label.text = message;
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"添加" style:UIBarButtonItemStyleBordered target:self action:@selector(rightMethods)];
}

- (void)rightMethods
{
    NSLog(@"...........");
}

 DisclosureButtonController文件

- (void)viewDidLoad
{
    NSArray *array = [[NSArray alloc]initWithObjects:@"The First One",@"The Second One",@"The Thr One",@"The Fou One", nil];
    self.list = array;
    [array release];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"last Page" style:UIBarButtonItemStyleBordered target:self action:@selector(uppage)];

}

- (void)uppage
{
    [self.navigationController popToRootViewControllerAnimated:YES];
}

- (void)dealloc
{
    [list release];
    [super dealloc];
}

#pragma mark -
#pragma mark Table View Data Source Methods

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [self.list count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *theNewKey = @"theNewKey";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:theNewKey];
    if(cell == nil){
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:theNewKey] autorelease];
    }
    NSUInteger row = [indexPath row];
    NSString *theString = [list objectAtIndex:row];
    cell.textLabel.text = theString;
    
    return cell;
}


#pragma mark -
#pragma mark Table Delegate Methods

- (UITableViewCellAccessoryType)tableView:(UITableView *)tableView accessoryTypeForRowWithIndexPath:(NSIndexPath *)indexPath
{
    return UITableViewCellAccessoryDetailDisclosureButton;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Waring" message:@"You Pressed" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
    [alert show];
    [alert release];
}

- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{
    if(detailController == nil){
        detailController = [[DisclosureDetailController alloc] initWithNibName:@"DisclosureDetail" bundle:nil];
    }
    
    detailController.title = @"The Detail View";
    
    NSUInteger row = [indexPath row];
    
    NSString *warItem = [list objectAtIndex:row];
    NSString *detailSelect = [[NSString alloc] initWithFormat:@"You Pressed Is %@",warItem];
    detailController.message = detailSelect;
    [detailSelect release];
    [self.navigationController pushViewController:detailController animated:YES];

}
 
分享到:
评论

相关推荐

    iOS如何改变UIBarButtonItem的大小详解

    在iOS开发中,导航栏(UINavigationController)是应用界面中不可或缺的部分,通常包含左右两侧的UIBarButtonItem,用于展示图标或文字按钮。在某些情况下,我们可能需要自定义这些按钮的大小,使其更适合应用的设计...

    iOS应用开发中导航栏按钮UIBarButtonItem的添加教程

    通过以上步骤,你已经学会了如何在iOS应用中使用UINavigationController添加UIBarButtonItem,以及如何在不同视图控制器之间进行导航。这只是一个基础教程,实际开发中,你可能需要处理更多复杂的情况,如自定义按钮...

    NavBar 的一个小例子

    本示例以"NavBar 的一个小例子"为标题,通过Objective-C编程语言来实现,揭示了如何在iPhone应用中创建和自定义NavBar。 首先,我们需要了解NavBar的基本概念。NavBar属于UINavigationController的一部分,它位于...

    ios中navigationcontroller实现实例

    在iOS应用开发中,`UINavigationController` 是一个至关重要的组件,它管理着一系列 `UIViewController` 对象,并在屏幕顶部提供了一个导航栏,用于在这些视图控制器之间进行切换。在这个实例中,我们将深入探讨如何...

    IOS应用源码之仿Instagram, Path, DailyBooth底部导航风格 .rar

    在这个例子中,我们将重点关注UITabBarController,它是实现底部导航的核心组件。 2. **UITabBarController**: 这个控制器管理一组子视图控制器,每个子视图控制器对应底部导航栏的一个选项。通过设置tabBarItem...

    QQ侧边菜单效果

    在这个例子中,我们会在导航控制器的左侧设置一个UIBarButtonItem,用户点击这个按钮来触发侧边菜单的显示与隐藏。 5. **坐标与大小的改变**: 当用户点击UIBarButtonItem时,我们需要动态调整标签控制器的frame...

    iOS iphone工具栏创建简单的多视图

    本教程将深入讲解如何在iPhone应用中使用工具栏(Toolbar)来实现简单的多视图切换,这对于初学者来说是一个非常实用的例子。 首先,我们需要了解iOS的基础架构。iOS应用基于Cocoa Touch框架,其中UIWindow、...

    UINavigationBar的层次说明(附:简单实例源码)

    在iOS开发中,`UINavigationBar`是苹果提供的一个关键组件,它位于每个导航控制器(UINavigationController)的顶部,用于展示应用的导航结构。`UINavigationBar`通常包含一个标题,左侧和右侧的按钮,以及可能的...

    swift-系统返回按钮事件拦截Swift版本

    在这个例子中,`canPop()` 方法是关键,你可以根据具体需求在此处添加判断条件。如果满足返回条件,就调用父类的`popViewControllerAnimated(_:)`方法,否则返回`nil`阻止返回操作。 另外,如果你想要改变返回按钮...

    ios-轻松实现导航栏有无透明过度的配置.zip

    在UIKit框架中,`UINavigationController`类负责管理一个堆栈的`UIViewController`实例,并提供了一个默认的`UINavigationBar`。导航栏的透明度可以通过`isTranslucent`属性来设置,该属性默认为`true`,表示导航栏...

    关于iOS导航栏返回按钮问题的解决方法

    在iOS开发中,导航栏(`UINavigationController`)是应用界面常见的组件,它提供了一种在多个控制器之间导航的方式。导航栏通常包含一个左侧面的返回按钮,用于回退到上一个视图控制器。本篇文章将详细介绍如何解决...

    ios仿侧边抽屉效果实现代码

    首先,我们从提供的代码片段中可以看到,开发者在`AppDelegate.m`文件中设置了应用的主窗口,并且初始化了一个导航控制器(`UINavigationController`)作为根视图控制器。这是iOS应用的基本结构,导航控制器可以管理...

    swift4 使用DrawerController实现侧滑菜单功能的示例代码

    let drawerController = DrawerController(centerViewController: UINavigationController(rootViewController: ViewController()), leftDrawerViewController: UINavigationController(rootViewController: ...

Global site tag (gtag.js) - Google Analytics