当前位置:  编程技术>移动开发
本页文章导读:
    ▪多线程GCD,UIActivityIndicatorView的等候画面        多线程GCD,UIActivityIndicatorView的等待画面 //在Login Lable上添加spinner UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; [spinner startAni.........
    ▪ UINavigationController详解与施用(一)添加UIBarButtonItem        UINavigationController详解与使用(一)添加UIBarButtonItem 2012.12.28效果图:[img][/img]这次添加的导航条及上面的左右按钮,都是再代码中进行添加,并未使用xib文件进行界面设计。一、新建一个Empty .........
    ▪ UINavigationController详解与施用(二)页面切换和segmentedController       UINavigationController详解与使用(二)页面切换和segmentedController UINavigationController详解与使用(一)添加UIBarButtonItem是上篇,我们接着讲UINavigationController的重要作用,页面的管理和切换。运行效果.........

[1]多线程GCD,UIActivityIndicatorView的等候画面
    来源: 互联网  发布时间: 2014-02-18
多线程GCD,UIActivityIndicatorView的等待画面
    //在Login Lable上添加spinner
    UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
    [spinner startAnimating];
    spinner.center = self.loginButton.center;
    [self.view addSubview:spinner]; 
   //多线程等待login的返回值    
    dispatch_queue_t downloadQueue = dispatch_queue_create("data downloader",NULL);
    dispatch_async(downloadQueue,^{
        NSString *returnedValue = [self loginConnection];
        dispatch_async(dispatch_get_main_queue(),^{
         if(returnedValue == @"ok"){
                [self performSegueWithIdentifier:@"ShowHomePage" sender:self];
            }else(returnedValue == @"Authentification Failed"){
                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Authentification Failed." message:@"Authentification Failed." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
                [alert show];
                spinner.hidden = YES;
                [self.loginButton setTitle:@"Login" forState:UIControlStateNormal];
            }
        });
    });

注1:[self loginConnection] 不应涉及界面元素的操作,例如不能把 UIAlertView 代码放入loginConnection中。
注2:[self loginConnection] 中的方法必须是同步的,比如sendSynchronousRequest

 


    
[2] UINavigationController详解与施用(一)添加UIBarButtonItem
    来源: 互联网  发布时间: 2014-02-18
UINavigationController详解与使用(一)添加UIBarButtonItem
2012.12.28

效果图:
[img]

[/img]

这次添加的导航条及上面的左右按钮,都是再代码中进行添加,并未使用xib文件进行界面设计。

一、新建一个Empty App工程:UINavigationControllerDemo

二、创建一个View Controller,命名为RootViewController:依次选择File——New——New File,默认勾上With XIB for user interface.

三、打开AppDelegate.h,向其中添加属性:
#import <UIKit/UIKit.h>



@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) UINavigationController *navController;

@end


四、在AppDelegate.m 文件的didFinishLaunchingWithOptions方法中创建添加navController,RootViewController视图。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    RootViewController *rootView = [[RootViewController alloc] init];
    rootView.title = @"Root View";
    
    self.navController = [[UINavigationController alloc] init];
    [self.navController pushViewController:rootView animated:YES];
    [self.window addSubview:self.navController.view];
    [self.window makeKeyAndVisible];
    return YES;
}


五、添加UIBarButtonItem

bar ButtonItem分左右UIBarButtonItem。我们把左右的都添加上去。

在RootViewController.m中添加代码如下:
- (void)viewDidLoad
{
    [super viewDidLoad];

    UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(selectLeftAction:)];
    self.navigationItem.leftBarButtonItem = leftButton;
    
    UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd  target:self action:@selector(selectRightAction:)];
    self.navigationItem.rightBarButtonItem = rightButton;


六、响应UIBarButtonItem的事件的实现

我们在 action:@selector(selectLeftAction:);

action添加了selectLeftAction和selectRightAction

在RootViewController.m文件中添加代码实现:
-(void)selectLeftAction:(id)sender
{
    UIAlertView *alter = [[UIAlertView alloc] initWithTitle:@"提示" message:@"你点击了导航栏左按钮" delegate:self  cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
    [alter show];
}

-(void)selectRightAction:(id)sender
{
    UIAlertView *alter = [[UIAlertView alloc] initWithTitle:@"提示" message:@"你点击了导航栏右按钮" delegate:self  cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
    [alter show];
}


这里重点介绍下

UIBarButtonItem *leftButton = [[UIBarButtonItemalloc]initWithBarButtonSystemItem:UIBarButtonSystemItemActiontarget:selfaction:@selector(selectLeftAction:)];

UIBarButtonSystemItemAction的风格,这是系统自带的按钮风格,看下图,你不用一个个试验,你也知道想用那个item,如下图:
[img]

[/img]





    
[3] UINavigationController详解与施用(二)页面切换和segmentedController
    来源: 互联网  发布时间: 2014-02-18
UINavigationController详解与使用(二)页面切换和segmentedController
UINavigationController详解与使用(一)添加UIBarButtonItem是上篇,我们接着讲UINavigationController的重要作用,页面的管理和切换。


运行效果图:
[img]

[/img]

[img]

[/img]

1、RootView 跳到SecondView

首先我们需要新一个View。新建SecondView,按住Command键然后按N,弹出新建页面,我们新建SecondView

2、为Button 添加点击事件,实现跳转
在RootViewController.xib中和RootViewController.h文件建立连接
在RootViewController.m中实现代码,alloc一个SecondViewController,用pushViewController到navigationController中去,并为

SecondViewController这是title为    secondView.title =@"Second View"; 默认情况下,titie为下个页面返回按钮的名字。
- (IBAction)gotoSecondView:(id)sender {
    SecondViewController *secondView = [[SecondViewController alloc] init];
    [self.navigationController pushViewController:secondView animated:YES];
    secondView.title = @"Second View";
}


3.1、添加segmentedController
     在RootViewController.m的viewDidLoad添加如下代码:
 NSArray *array = [NSArray arrayWithObjects:@"鸡翅",@"排骨", nil];
    UISegmentedControl *segmentedController = [[UISegmentedControl alloc] initWithItems:array];
    segmentedController.segmentedControlStyle = UISegmentedControlSegmentCenter;

    [segmentedController addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
    self.navigationItem.titleView = segmentedController;


3.2[segmentedController addTarget:selfaction:的实现
-(void)segmentAction:(id)sender
{
    switch ([sender selectedSegmentIndex]) {
        case 0:
        {
            UIAlertView *alter = [[UIAlertView alloc] initWithTitle:@"提示" message:@"你点击了鸡翅" delegate:self  cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
            [alter show];

        }
        break;
    case 1:
        {
            UIAlertView *alter = [[UIAlertView alloc] initWithTitle:@"提示" message:@"你点击了排骨" delegate:self  cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
            [alter show];
        }
        break;
        
        default:
            break;
    }
}


4、自定义backBarButtonItem

左上角的返回上级View的barButtonitem的名字是上级目录的Title,如果title或者适合做button的名字,怎么办呢?我们可以自己定义
代码如下:
 UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"根视图" style:UIBarButtonItemStyleDone target:nil action:nil];
    self.navigationItem.backBarBu

我是新手,主意添加位置:RootViewControll.m中
  
- (void)viewDidLoad
{
    [super viewDidLoad];
    //add leftButton 添加左按钮
    UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(selectLeftAction:)];
    self.navigationItem.leftBarButtonItem = leftButton;
    
    // add rightButton 添加右按钮
    UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd  target:self action:@selector(selectRightAction:)];
    self.navigationItem.rightBarButtonItem = rightButton;
    
    
    // add backButton 添加返回按钮
    UIBarButtonItem *backButton = [[UIBarButtonItem alloc]initWithTitle:@"Root View" style:UIBarButtonItemStyleDone target:self action:nil];
    self.navigationItem.backBarButtonItem = backButton;
    
    //add SegmentedControl on Navigation  添加分段
    NSArray *array = [[NSArray alloc] initWithObjects:@"one",@"two" ,@"three",nil];
    UISegmentedControl *segmentdeController = [[UISegmentedControl alloc] initWithItems:array];
    segmentdeController.segmentedControlStyle = UISegmentedControlSegmentCenter;
    [segmentdeController addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
    self.navigationItem.titleView = segmentdeController;
    
    
    
    
}


5、自定义title
UINavigationController的title可以用别view替代,比如用UIButton UILable等,下面我用UIButton.
在SecondViewController.m中添加下面如下:
- (void)viewDidLoad
{
    [super viewDidLoad];
    UIButton *button = [UIButton buttonWithType: UIButtonTypeRoundedRect];
    [button setTitle: @"自定义title" forState: UIControlStateNormal];
    [button sizeToFit];
    self.navigationItem.titleView = button;}

    
最新技术文章:
▪Android开发之登录验证实例教程
▪Android开发之注册登录方法示例
▪Android获取手机SIM卡运营商信息的方法
▪Android实现将已发送的短信写入短信数据库的...
▪Android发送短信功能代码
▪Android根据电话号码获得联系人头像实例代码
▪Android中GPS定位的用法实例
▪Android实现退出时关闭所有Activity的方法
▪Android实现文件的分割和组装
▪Android录音应用实例教程
▪Android双击返回键退出程序的实现方法
▪Android实现侦听电池状态显示、电量及充电动...
▪Android获取当前已连接的wifi信号强度的方法
▪Android实现动态显示或隐藏密码输入框的内容
▪根据USER-AGENT判断手机类型并跳转到相应的app...
▪Android Touch事件分发过程详解
▪Android中实现为TextView添加多个可点击的文本
▪Android程序设计之AIDL实例详解
▪Android显式启动与隐式启动Activity的区别介绍
▪Android按钮单击事件的四种常用写法总结
▪Android消息处理机制Looper和Handler详解
▪Android实现Back功能代码片段总结
▪Android实用的代码片段 常用代码总结
▪Android实现弹出键盘的方法
▪Android中通过view方式获取当前Activity的屏幕截...
▪Android提高之自定义Menu(TabMenu)实现方法
▪Android提高之多方向抽屉实现方法
▪Android提高之MediaPlayer播放网络音频的实现方法...
▪Android提高之MediaPlayer播放网络视频的实现方法...
▪Android提高之手游转电视游戏的模拟操控
 


站内导航:


特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

©2012-2021,,E-mail:www_#163.com(请将#改为@)

浙ICP备11055608号-3