iOS中使用UItableviewcell实现团购和微博界面的示例

2020-01-14 18:26:55于海丽

//
//  Created by apple on 14-5-29.
//  Copyright (c) 2014年 itcase. All rights reserved.
//

 

#import "YYViewController.h"
#import "YYtg.h"
#import "YYtgcell.h"

@interface YYViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (strong, nonatomic) IBOutlet UITableView *tableview;

@property(strong,nonatomic)NSArray *tg;
@end


复制代码
@implementation YYViewController

 

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.tableview.rowHeight=80.f;
}
#pragma mark-  懒加载
-(NSArray *)tg
{
    if (_tg==nil) {
        NSString *fullpath=[[NSBundle mainBundle]pathForResource:@"tgs.plist" ofType:nil];
        NSArray *temparray=[NSArray arrayWithContentsOfFile:fullpath];
        
        NSMutableArray *arrayM=[NSMutableArray arrayWithCapacity:temparray.count];
        for (NSDictionary *dict in temparray) {
            YYtg *tg=[YYtg tgWithDict:dict];
            [arrayM addObject:tg];
        }
        _tg=[arrayM mutableCopy];
    }
    return _tg;
}


#pragma mark- xib创建cell数据处理
#pragma mark 多少组
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
#pragma mark多少行
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.tg.count;
}
#pragma mark设置每组每行
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identifier= @"tg";
    YYtgcell *cell=[tableView dequeueReusableCellWithIdentifier:identifier];
    if (cell==nil) {
        //如何让创建的cell加个戳
        //对于加载的xib文件,可以到xib视图的属性选择器中进行设置