分组静态表视图

来源:互联网 发布:vb insert into 语法 编辑:程序博客网 时间:2024/04/29 04:52

前面的表视图都是动态的,其中单元格数目都是未知的;接下来我将讲述的是静态表视图,将表分成许多“孤岛”,每一节中的单元格数目事先是确定的;

1,像故事版中拖入一个TableViewController,将tableView的属性检查器设置如下图(1):


(1)


2,在第一节的Table View  Section中,将其属性检查器中的row设置为2(单元格数目),拖入两个textfield控件,将其设置为输出口,如图(2):


(2)

3,在第二节中,将row设置为1,拖入一个button控件,设置为动作,如图(3):


      (3)

4,在第三节中,将row设置为1,拖入一个label标签,并在table view section 属性检查器中,从Accessory 下拉表中选择Disclosure Indicator(扩展指示器),如图(4):



5,代码如下:

(1),.h文件中:

@interface ViewController :UITableViewController

@property (strong,nonatomic) IBOutletUITextField *txtUserName;


@property (strong,nonatomic) IBOutletUITextField *txtPwd;


- (IBAction)login:(id)sender;




@end



(2),.m文件中:

#import "ViewController.h"


@interface ViewController ()


@end


@implementation ViewController


- (void)viewDidLoad

{

    [superviewDidLoad];

// Do any additional setup after loading the view, typically from a nib.

}


- (void)didReceiveMemoryWarning

{

    [superdidReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


- (IBAction)login:(id)sender {

    

    if([self.txtPwd.textisEqualToString:@"123"]&&[self.txtUserName.textisEqualToString:@"tony"]){

        

       NSLog(@"登录成功");

        

        [self.txtPwdresignFirstResponder];

        [self.txtUserNameresignFirstResponder];

    

    }else{

       NSLog(@"您的输入有误");

    

    }

    

    

}

@end


备注:这里的单元格数都是事先确定的,我们不需要在静态表中实现数据源与委托协议的方法,因此不需要实现如下两个方法:

(1),-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;


(2),-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;



0 0
原创粉丝点击