iOS开发学习笔记 UITableview

预备

    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  




效果图







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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值