当前位置:  编程技术>移动开发
本页文章导读:
    ▪Navigation + Tab Bar 惯用组合框架        Navigation + Tab Bar 常用组合框架         看到很多项目中都采用的是Navigation加Tab Bar组合到一起,完成视图切换操作,在导航栏上添加基本按钮,给予响应时间,让应用给用户更好的体验,所.........
    ▪ 判断Wifi 联接        判断Wifi 连接private boolean checkConnection(){ boolean connected = false; ConnectivityManager cm = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE); if (cm != null) { NetworkInfo[] netInfo = cm.getAllNetworkInfo(); .........
    ▪ 机房收费系统之下机、上机       机房收费系统之上机、下机    上机流程图:   对应的代码: '################################################################# '上机,将上机记录写入到上机记录表里 '#############################################.........

[1]Navigation + Tab Bar 惯用组合框架
    来源: 互联网  发布时间: 2014-02-18
Navigation + Tab Bar 常用组合框架

        

看到很多项目中都采用的是Navigation加Tab Bar组合到一起,完成视图切换操作,在导航栏上添加基本按钮,给予响应时间,让应用给用户更好的体验,所以本菜鸟写了这个这样一个Demo,仅供学习


所创建工程模板是最后一个 Empty Application

      

先看运行效果:


第一个视图,点击按钮切换视图,点击导航栏上按钮可以切换回去

       


第二个视图设置了背景颜色和透明度  第三个视图添加了背景图片


      


第四个视图,在导航栏上添加了两个按钮,左边按钮属于自定义标题,右边按钮是系统的图标,点击左按钮弹出一个警告,右边按钮没有添加响应事件,点击后没反应


     


Tab Bar上添加的都是自定义图片


框架组合的主要代码,在AppDelegate.m中

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
    
    _tabBarController = [[UITabBarController alloc] init];
    _tabBarController.delegate = self;
    

    FirstViewController *firstViewController = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
    
    SecondViewController *secondViewController = [[SecondViewController alloc] initWithNibName:@"secondViewController" bundle:nil];
    
    ThirdViewController *thirdViewController = [[ThirdViewController alloc] initWithNibName:@"ThirdViewController" bundle:nil];
    
    FourViewController *fourViewController = [[FourViewController alloc] initWithNibName:@"FourViewController" bundle:nil];
    
    UINavigationController *navFirst = [[UINavigationController alloc] initWithRootViewController:firstViewController];
//    在加载图片是把标题都覆盖了,所以运行效果并没有显示这些文字
    navFirst.title = @"第一个视图";
    
    UINavigationController *navSecond = [[UINavigationController alloc] initWithRootViewController:secondViewController];
    navSecond.title = @"第二个视图";
    
    UINavigationController *navThird = [[UINavigationController alloc] initWithRootViewController:thirdViewController];
    navThird.title = @"第三个视图";
    
    UINavigationController *navFour = [[UINavigationController alloc] initWithRootViewController:fourViewController];
    navFour.title = @"第四个视图";
    
    
    _tabBarController.viewControllers = [NSArray arrayWithObjects:navFirst,navSecond,navThird,navFour, nil];
    _window.rootViewController = _tabBarController;
    
    [self.window addSubview:firstViewController.view];
    [self.window makeKeyAndVisible];
    return YES;
}

第一个视图切换按钮响应事件

- (IBAction)switchView:(id)sender {
    
    FirstViewController *firstController = [[FirstViewController alloc] init];
    [self.navigationController pushViewController:firstController animated:YES];
    firstController.title = @"第一个视图另一个视图";
}

第四个视图添加两个按钮方法,在最后一个控制机的.m文件中的-(void)viewDidLoad方法中


- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithTitle:@"测试"
                                                                   style:UIBarButtonItemStylePlain target:self
                                                                  action:@selector(pullWarn)];
    self.navigationItem.leftBarButtonItem = leftButton;
    
    UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:self action:nil];
    self.navigationItem.rightBarButtonItem = rightButton;
}



源代码:http://download.csdn.net/detail/duxinfeng2010/4576308








    
[2] 判断Wifi 联接
    来源: 互联网  发布时间: 2014-02-18
判断Wifi 连接
private boolean checkConnection(){ 
 
 
boolean connected = false; 
ConnectivityManager cm =  (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE); 
 
if (cm != null) { 
NetworkInfo[] netInfo = cm.getAllNetworkInfo(); 
 
for (NetworkInfo ni : netInfo) { 
if ((ni.getTypeName().equalsIgnoreCase("WIFI") 
|| ni.getTypeName().equalsIgnoreCase("MOBILE")) 
& ni.isConnected() & ni.isAvailable()) { 
connected = true; 
     } 
 
   } 
 } 
 
 
return connected; 


    
[3] 机房收费系统之下机、上机
    来源: 互联网  发布时间: 2014-02-18
机房收费系统之上机、下机

    上机流程图:

 

对应的代码:

'#################################################################
'上机,将上机记录写入到上机记录表里
'#################################################################
Private Sub cmdOn_Click()
    Dim strSQL As String, strSQL2 As String, strSQL3 As String
    Dim strMsgText As String, strMsgText2 As String, strMsgText3 As String
    Dim objRst As ADODB.Recordset, objRst2 As ADODB.Recordset, objRst3 As ADODB.Recordset
    
    '让下机日期和时间,消费时间和金额为空
    txtOutDate.Text = ""
    txtOutTime.Text = ""
    txtPayTime.Text = ""
    txtPayMoney.Text = ""
    
    If txtCardNo.Text = "" Then
        '判断卡号是否为空
        MsgBox "请输入卡号!", vbOKOnly, "警告!"
        txtCardNo.SetFocus
        Exit Sub
    Else
        If Len(txtCardNo.Text) > 10 Then
            '判断输入卡号是否超过设定的长度,防止出错
            MsgBox "卡号过长,请输入长度<10的卡号", vbOKOnly, "警告!"
            txtCardNo.SetFocus
            Exit Sub
        End If
        '查询数据库里学生基本信息表
        Set objRst = New ADODB.Recordset
        strSQL = "select * from student_Info where cardNo='" & Trim(txtCardNo.Text) & "'"
        Set objRst = ExecuteSQL(strSQL, strMsgText)
        If objRst.BOF And objRst.EOF Then
            '判读该卡号是否存在
            MsgBox "该卡号未注册!", vbOKOnly, "警告!"
            txtCardNo.Text = ""
            txtCardNo.SetFocus
            Exit Sub
        Else
            '判断余额是否充足
            If objRst.Fields(3) < GetLeastMoney() Then
                MsgBox "余额只有" & objRst.Fields(3) & ",少于最少金额,请先充值!", vbOKOnly, "警告!"
                Exit Sub
            Else
            
                '判断该卡号是否正在上机
                Set objRst3 = New ADODB.Recordset
                strSQL3 = "select * from online_Info where cardNo='" & Trim(txtCardNo.Text) & "' and outDate is null"
                Set objRst3 = ExecuteSQL(strSQL3, strMsgText3)
                If Not (objRst3.BOF And objRst3.EOF) Then
                    Label1.Caption = "该卡正在上机!"
                    txtCardNo.SetFocus
                    Exit Sub
                Else
                
                    '显示该卡号的一些基本信息
                    txtStudentNo.Text = checkField(objRst.Fields(0))
                    txtDepartment.Text = checkField(objRst.Fields(4))
                    txtType.Text = checkField(objRst.Fields(14))
                    txtStudentName.Text = checkField(objRst.Fields(1))
                    txtSex.Text = checkField(objRst.Fields(7))
                    txtOnDate.Text = Date
                    'onTime = Time
                    txtOnTime.Text = Time
                    txtAllCash.Text = checkField(objRst.Fields(3))
            
                    '将上机前的余额提出来,用于下机时计算余额
                    'curAllCash = checkField(objRst.Fields(3))
                    Label1.Caption = "欢迎光临!"
            
                    '将该卡上机的信息填入到online_Info表里
                    Set objRst2 = New ADODB.Recordset
                    strSQL2 = "select * from online_Info "
                    Set objRst2 = ExecuteSQL(strSQL2, strMsgText2)
                    'objRst2.MoveLast
                    objRst2.AddNew
                    objRst2.Fields(0) = txtCardNo.Text
                    objRst2.Fields(1) = txtStudentName.Text
                    objRst2.Fields(2) = Date
                    objRst2.Fields(3) = Time
                    objRst2.Fields(4) = Null
                    objRst2.Fields(5) = Null
                    objRst2.Update
                    '查询此时正在上机的人数。(可以直接加1)
                    lblPeopleCount.Caption = GetPeopleCount()
                    PeopleCount = GetPeopleCount()   '保存正在上机的人数
                    objRst2.Close
            
                    objRst.Close
                End If
            End If
        End If
    End If
    
            
        
End Sub

 


下机的流程图:

 

 

对应的代码:

 

'#####################################################################
'下机,计算余额,将余额写入学生信息表里,和上机信息表里
'#####################################################################
Private Sub cmdOff_Click()

    Dim strSQL As String, strSQL2 As String, strSQL3 As String
    Dim strMsgText As String, strMsgText2 As String, strMsgText3 As String
    Dim objRst As ADODB.Recordset, objRst2 As ADODB.Recordset, objRst3 As ADODB.Recordset
    Dim intTime As Single
    Dim fixedRate As Single
    Dim AllMoney As Currency
    Dim pay As Currency


    If txtCardNo.Text = "" Then
        '判断卡号是否为空
        MsgBox "请输入卡号!", vbOKOnly, "警告!"
        txtCardNo.SetFocus
        Exit Sub
    Else
        If Len(txtCardNo.Text) > 10 Then
            '判断输入卡号是否超过设定的长度,防止出错
            MsgBox "卡号过长,请输入长度<10的卡号", vbOKOnly, "警告!"
            txtCardNo.SetFocus
            Exit Sub
        End If
    End If
    Set objRst = New ADODB.Recordset
    strSQL = "select * from student_Info where cardNo='" & Trim(txtCardNo.Text) & "'"
    Set objRst = ExecuteSQL(strSQL, strMsgText)
    If objRst.BOF And objRst.EOF Then
        '判读该卡号是否存在
        MsgBox "该卡号未注册!", vbOKOnly, "警告!"
        txtCardNo.Text = ""
        txtCardNo.SetFocus
        Exit Sub
        
    End If
    objRst.Close
    strSQL = ""
    strMsgText = ""
    
    
    
    Set objRst = New ADODB.Recordset
    strSQL = "select * from online_Info where cardno='" & Trim(txtCardNo.Text) & "' and outDate is null "
    Set objRst = ExecuteSQL(strSQL, strMsgText)
    If objRst.BOF And objRst.EOF Then
        '判断该卡是否正在上机
        Label1.Caption = "该卡没有上机!"
        txtCardNo.SetFocus
        Exit Sub
    Else
        '显示下机的一些信息
        txtOutDate.Text = Date
        outTime = Time
        txtOutTime.Text = outTime
        
        onTime = CDate(Format(objRst.Fields("onTime"), "hh:mm:ss"))
    
        txtCardNo.Text = checkField(objRst.Fields("cardNo"))
        txtStudentName.Text = checkField(objRst.Fields("studentName"))
        txtOnDate.Text = checkField(objRst.Fields("onDate"))
        txtOnTime.Text = checkField(objRst.Fields("onTime"))
        
        Set objRst3 = New ADODB.Recordset
        strSQL3 = "select * from student_Info where cardNo='" & txtCardNo.Text & "'"
        Set objRst3 = ExecuteSQL(strSQL3, strMsgText3)
        txtStudentNo.Text = objRst3.Fields("studentNo")
        txtDepartment.Text = objRst3.Fields("department")
        txtSex.Text = objRst3.Fields("sex")
        txtType.Text = "固定用户"
        
        '删除该记录,将此时信息填入online_Info表里
        objRst.Delete
        objRst.AddNew
        objRst.Fields(0) = txtCardNo.Text
        objRst.Fields(1) = txtStudentName.Text
        objRst.Fields(2) = txtOnDate.Text
        objRst.Fields("onTime") = txtOnTime.Text
        objRst.Fields(4) = txtOutDate.Text
        objRst.Fields("outTime") = txtOutTime.Text
        objRst.Fields(9) = "正常下机"
        'intTime = Val(txtOutTime.Text - txtOnTime.Text)
        
        '计算上机的时间
        intTime = (outTime - onTime) * 24 * 2
                
         Set objRst2 = New ADODB.Recordset
         strSQL2 = "select * from basicDate_Info "
         Set objRst2 = ExecuteSQL(strSQL2, strMsgText2)
         '查询固定用户30分钟的费用
         fixedRate = Val(objRst2.Fields(0))
         If intTime < (GetPreparTime() / 30) Then
             '判断上机时间是否超过了准备时间,没超过则花费为0
             objRst.Fields("pay") = 0
             objRst.Fields("allCash") = GetAllMoney(txtCardNo.Text)
         Else
             If intTime <= (GetLeastTime() / 30) Then
                 '判断上机时间是否超过半个小时,没则当成已经上了30分钟
                 objRst.Fields("pay") = fixedRate
                 AllMoney = GetAllMoney(txtCardNo.Text) - fixedRate
                 objRst.Fields("allCash") = AllMoney     '将余额写入上机记录表里
                 WriteAllMoney txtCardNo.Text, AllMoney  '将余额写入学生基本信息表里
             Else
                 If intTime > Int(intTime) Then
                     intTime = Int(intTime) + 1
                 Else
                     intTime = Int(intTime)
                 End If
                 pay = fixedRate * intTime
                 objRst.Fields("pay") = pay
                 AllMoney = GetAllMoney(txtCardNo.Text) - pay
                 objRst.Fields("allCash") = AllMoney    '将余额写入上机记录表里
                 WriteAllMoney txtCardNo.Text, AllMoney  '将余额写入学生基本信息表里
             End If
         End If
         
         '显示消费的时间金额,和余额
         txtPayTime.Text = Format(outTime - onTime, "hh-mm-ss")
         txtPayMoney.Text = objRst.Fields(6)
         txtAllCash.Text = GetAllMoney(txtCardNo.Text)     '- objRst.Fields(6)
         Label1.Caption = "欢迎下次再来!"
         
         objRst.Fields(7) = txtAllCash.Text    '将余额写到online_Info表里
         
         lblPeopleCount.Caption = GetPeopleCount()  '显示正在上机人数
         PeopleCount = GetPeopleCount()
         objRst.Update
        
         objRst.Close
         objRst2.Close
         objRst3.Close
         
    End If
    
        
End Sub


 

其中,有一些是自己写的函数。GetPeopleCount()是取得正在上机的函数,GetAllMoney(txtCardNo.Text)是取得余额的函数,GetLeastTime()是取得至少上机时间的函数,GetPreparTime()是取得准备上机时间,GetFixedRate()是取得固定用户30分钟的费用。

7楼tang_huan_116小时前很好,加油!6楼gwblue昨天 21:41很好,很详细继续加油!5楼lidaasky昨天 22:45登录方面,你可以尝试使用单if判断,嵌套的if容易搞混,图画的不错4楼yjjm1990昨天 22:40嗯,挺好的,就是if那样嵌套不好,还有自己注意一个变更的命名。很不错!加油!3楼hejingyuan6昨天 21:21哈哈,加油呀2楼lishehe昨天 20:58不错啊,学习了方法很多啊,相互交流1楼lfmilaoshi昨天 20:40图不错,很好n米老师

    
最新技术文章:
▪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