iOS开发学习笔记 UITableview

来源:互联网 发布:mac鼠标滚轮方向 编辑:程序博客网 时间:2024/05/18 04:52

预备

    1.工程勾选支持ARC
    2.利用IB拖一个UITableview并且连接委托




代码

       用UITableview实现简单的文字和图片显示

 
    #import <UIKit/UIKit.h>            @interface ViewController : UIViewController            @property (strong,nonatomic) IBOutlet UITableView *mtableview;      @property (strong,nonatomic) NSArray *list; //存储列表数据            @end  

    #import "ViewController.h"            @interface ViewController ()            @end            @implementation ViewController            @synthesize mtableview,list;            - (void)viewDidLoad      {          [super viewDidLoad];          // Do any additional setup after loading the view, typically from a nib.          NSArray *array = [[NSArray alloc]initWithObjects:@"NO.1",@"NO.2",@"NO.3",@"NO.4",@"NO.5",@"NO.6", nil];          list = array;      }            - (void)viewDidUnload      {          [super viewDidUnload];          // Release any retained subviews of the main view.      }            - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation      {          return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);      }            //数据源委托      //tableView一共有多少行数据      - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section      {          return [list count];      }            //每行数据的内容      - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath      {          static NSString *tableViewIdentifier = @"tableViewIdentifier";          UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:tableViewIdentifier];          if (cell == nil)          {              cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault                                            reuseIdentifier:tableViewIdentifier];          }                    NSUInteger row = [indexPath row];          cell.textLabel.text = [list objectAtIndex:row];                    //添加图片          UIImage *image = [UIImage imageNamed:@"1.png"];          [cell.imageView setImage:image];                    return cell;      }            @end  




效果图







        如有错误、疑问或者任何不合理的地方,请指教。谢谢。

原创粉丝点击