iOS 自定义UITableViewCell
2015-12-31 16:46
405 查看
#import <UIKit/UIKit.h> @interface AppDelegate : UIResponder <UIApplicationDelegate> @property (strong, nonatomic) UIWindow *window; @end
#import "AppDelegate.h" #import "AViewController.h" @implementation AppDelegate - (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]; AViewController *root = [AViewController new]; UINavigationController *navi = [[UINavigationController alloc] initWithRootViewController:root]; self.window.rootViewController = navi; [self.window makeKeyAndVisible]; return YES; } @end
#import <UIKit/UIKit.h> @interface AViewController : UIViewController<UITableViewDelegate,UITableViewDataSource> { // 呈现数据源的控件 UITableView *_tableView; // 数据源 NSArray *datas; } @end
#import "AViewController.h" #import "CumstomCell.h"//导入自定义的cell @implementation AViewController -(void)loadView { [super loadView]; // 不分组的plain样式 _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 568) style:UITableViewStylePlain]; // 数据源代理 _tableView.dataSource = self; _tableView.delegate = self; [self.view addSubview:_tableView]; } - (void)viewDidLoad { [super viewDidLoad]; NSString *str = @"A,B,C,D,E,F,G,H,I,J,K,L,M,N"; datas = [str componentsSeparatedByString:@","]; } #pragma mark -数据源配置- // 配置tablview显示多少行数据 -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return datas.count; } -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 120.0f; } // 每个cell显示什么内容 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *indentity = @"cell"; //使用自定义的cell CumstomCell *cell = [_tableView dequeueReusableCellWithIdentifier:indentity]; if (cell == nil) { cell=[[CumstomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:indentity]; } //NSLog(@"%d",indexPath.row); //NSString *t = [datas objectAtIndex:indexPath.row]; //cell.textLabel.text = t; cell.imgView1.image = [UIImage imageNamed:@"123.jpg"]; cell.imgView2.image = [UIImage imageNamed:@"123.jpg"]; cell.imgView3.image = [UIImage imageNamed:@"123.jpg"]; return cell; } @end
#import <UIKit/UIKit.h> @interface CumstomCell : UITableViewCell @property(nonatomic,strong)UIImageView *imgView1; @property(nonatomic,strong)UIImageView *imgView2; @property(nonatomic,strong)UIImageView *imgView3; @end
#import "CumstomCell.h" @implementation CumstomCell @synthesize imgView1=_imgView1; @synthesize imgView2=_imgView2; @synthesize imgView3=_imgView3; -(void)dealloc{ /* [_imgView1 release]; [_imgView2 release]; [_imgView3 release]; [super dealloc]; */ _imgView1 = nil; _imgView2 = nil; _imgView3 = nil; } /** * 重写该方法 */ -(UITableViewCell *)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) { self.imgView1 = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 80, 100)]; //self.imgView1.backgroundColor = [UIColor redColor]; [self.contentView addSubview:self.imgView1]; self.imgView2 = [[UIImageView alloc] initWithFrame:CGRectMake(10+80+10, 10, 80, 100)]; //self.imgView2.backgroundColor = [UIColor redColor]; [self.contentView addSubview:self.imgView2]; self.imgView3 = [[UIImageView alloc] initWithFrame:CGRectMake(10+2*80+2*10, 10, 80, 100)]; //self.imgView3.backgroundColor = [UIColor redColor]; [self.contentView addSubview:self.imgView3]; } return self; } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; // Configure the view for the selected state } @end
相关文章推荐
- iOS:关于UITableView的性能优化点
- UIAlertController的使用
- LeetCode 96:Unique Binary Search Trees
- easyui样式及js导入顺序及刷新回车的问题
- 基于Silverlight/XAML开发嵌入式系统WinCE下应用程序UI
- IOS 16进制颜色字符串转UIColor
- Android多语言适配values文件夹命名
- easyui合并行(同列内容合并)
- IOS UI-滚动视图(UIScrollView)
- iOS UI-文本视图(UITextView)
- poj 1947 Rebuilding Roads 树形背包 ★
- mosquitto 管理常用命令
- UIScrollView配合定时器和手动实现图片轮播无限循环
- PowerBuilder
- 自定义UITableViewCell上的按钮点击事件处理
- 初识android自定义UI
- iOS 代码实现获得应用的版本号(Version/Build)
- Preparing to build session factory with filters : {}
- Arduino和Android通过OTG 通信
- ubuntu下使用quick2wire控制RespberryPi2的I2C