本邮件内容由第三方提供,如果您不想继续收到该邮件,可 点此退订 。
IOS开发之TableView、多个TableViewCell、自定义Cell、Cell上画画(故事板+代码方式) - 刘东寰 阅读原文»
最近要做一个项目,有个账户设置界面,看了微博、微信、QQ,他们的账号设置都比较原生态没做什么处理。春雨医生的账号不错,做了许多处理。不说废话直接上代码。
第一步:
//UserTableViewCell.h这里定义第一种Cell
#import <UIKit/UIKit.h>
@interface UserTableViewCell : UITableViewCell
@property (weak, nonatomic) IBOutlet UIImageView *userviewcellicon;
@property (weak, nonatomic) IBOutlet UILabel *userviewcellname;
@end
#import <UIKit/UIKit.h>
@interface UserTableViewCell : UITableViewCell
@property (weak, nonatomic) IBOutlet UIImageView *userviewcellicon;
@property (weak, nonatomic) IBOutlet UILabel *userviewcellname;
@end
//UserTableViewCell2.h这里定义第二种Cell,
#import <UIKit/UIKit.h>
@interface UserTableViewCell2 : UITableViewCell
@property (weak, nonatomic) IBOutlet UILabel *name;
@property (weak, nonatomic) IBOutlet UIImageView *userviewcell2image;
@end
#import <UIKit/UIKit.h>
@interface UserTableViewCell2 : UITableViewCell
@property (weak, nonatomic) IBOutlet UILabel *name;
@property (weak, nonatomic) IBOutlet UIImageView *userviewcell2image;
@end
故事板里的TableView和Cell的class和Cell的Identifier就不说了
例:
2、设计好了这些东西后,开始进TableViewController里了:
//UserTableViewController.h
#import <UIKit/UIKit.h>
@interface UserTableViewController : UITableViewController
@property(nonatomic,strong) NSDictionary *UserViewCellDic;
@property (nonatomic, strong) NSArray *listGroupname;
@end
#import <UIKit/UIKit.h>
@interface UserTableViewController : UITableViewController
@property(nonatomic,strong) NSDictionary *UserViewCellDic;
@property (nonatomic, strong) NSArray *listGroupname;
@end
//UserTableViewController.m
#import "UserTableViewController.h"
#import "UserTableViewCell.h"
#import "UserTableViewCell2.h"
@interface UserTableViewController ()
@end
@implementation UserTableViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.tableView.separatorStyle = UITableViewCellAccessoryNone;//去除分割线
NSBundle *bundle = [NSBundle mainBundle];
NSString *plistpath = ;
self.UserViewCellDic = [[NSDictionary alloc]initWithContentsOfFile:plistpath];
self.listGroupname = [self.UserViewCellDic allKeys];
self.listGroupname = [self.listGroupname sortedArrayUsingSelector:@selector(compare:)];//排序
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView//返回有几个Section
{
return [self.listGroupname count];
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section//Section头名字设为空
{
NSString *groupName = @" ";
return groupName;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section//每个section的行数
{
NSString *groupName = [self.listGroupname objectAtIndex:section];
NSArray *listitem = [self.UserViewCellDic objectForKey:groupName];
return [listitem count];
}
#pragma mark - TableViewDataSource
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *UserViewCellIdentifier = @"UserTableViewCell";
static NSString *UserViewCellIdentifier2 = @"UserTableViewCell2";
NSUInteger section = ;
NSUInteger row = ;
NSString *groupName = [self.listGroupname objectAtIndex:section];
NSArray *listitem = [self.UserViewCellDic objectForKey:groupName];
NSDictionary *rowDict = [listitem objectAtIndex:row];
if (0 == section) {
UserTableViewCell2 *cell = [tableView dequeueReusableCellWithIdentifier:UserViewCellIdentifier2];
cell.name.text = [rowDict objectForKey:@"name"];
NSString *imagePath = [rowDict objectForKey:@"image"];
imagePath = ;
cell.userviewcell2image.image = ;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;//最后的箭头
//画线
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 79, 320, 1)];
UIView *leftview = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 3, 80)];
UIView *rightview = [[UIView alloc]initWithFrame:CGRectMake(317, 0, 3, 80)];
view.backgroundColor = ;
leftview.backgroundColor = ;
rightview.backgroundColor = ;
[cell.contentView addSubview:view];
[cell.contentView addSubview:leftview];
[cell.contentView addSubview:rightview];
return cell;
}else{
UserTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:UserViewCellIdentifier];
cell.userviewcellname.text = [rowDict objectForKey:@"name"];
NSString *imagePath = [rowDict objectForKey:@"image"];
imagePath = ;
cell.userviewcellicon.image = ;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;//java之多线程(Thread) - 龚细军 阅读原文»
#import "UserTableViewController.h"
#import "UserTableViewCell.h"
#import "UserTableViewCell2.h"
@interface UserTableViewController ()
@end
@implementation UserTableViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.tableView.separatorStyle = UITableViewCellAccessoryNone;//去除分割线
NSBundle *bundle = [NSBundle mainBundle];
NSString *plistpath = ;
self.UserViewCellDic = [[NSDictionary alloc]initWithContentsOfFile:plistpath];
self.listGroupname = [self.UserViewCellDic allKeys];
self.listGroupname = [self.listGroupname sortedArrayUsingSelector:@selector(compare:)];//排序
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView//返回有几个Section
{
return [self.listGroupname count];
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section//Section头名字设为空
{
NSString *groupName = @" ";
return groupName;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section//每个section的行数
{
NSString *groupName = [self.listGroupname objectAtIndex:section];
NSArray *listitem = [self.UserViewCellDic objectForKey:groupName];
return [listitem count];
}
#pragma mark - TableViewDataSource
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *UserViewCellIdentifier = @"UserTableViewCell";
static NSString *UserViewCellIdentifier2 = @"UserTableViewCell2";
NSUInteger section = ;
NSUInteger row = ;
NSString *groupName = [self.listGroupname objectAtIndex:section];
NSArray *listitem = [self.UserViewCellDic objectForKey:groupName];
NSDictionary *rowDict = [listitem objectAtIndex:row];
if (0 == section) {
UserTableViewCell2 *cell = [tableView dequeueReusableCellWithIdentifier:UserViewCellIdentifier2];
cell.name.text = [rowDict objectForKey:@"name"];
NSString *imagePath = [rowDict objectForKey:@"image"];
imagePath = ;
cell.userviewcell2image.image = ;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;//最后的箭头
//画线
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 79, 320, 1)];
UIView *leftview = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 3, 80)];
UIView *rightview = [[UIView alloc]initWithFrame:CGRectMake(317, 0, 3, 80)];
view.backgroundColor = ;
leftview.backgroundColor = ;
rightview.backgroundColor = ;
[cell.contentView addSubview:view];
[cell.contentView addSubview:leftview];
[cell.contentView addSubview:rightview];
return cell;
}else{
UserTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:UserViewCellIdentifier];
cell.userviewcellname.text = [rowDict objectForKey:@"name"];
NSString *imagePath = [rowDict objectForKey:@"image"];
imagePath = ;
cell.userviewcellicon.image = ;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;//java之多线程(Thread) - 龚细军 阅读原文»
1 package DEMO;
2 //主线程
3 public class Example12_2 {
4 public static void main(String [] args )
5 {
6 Thread mydad ; //用Thread声明线程
7 Thread mymom ;
8 baba ba ; //ba是目标对象
9 mom ma ;
10 ba = new baba(); //创建目标对象
11 ma = new mom();
12 mydad = new Thread(ba); //创建线程,其目标对象是bab
13 mymom = new Thread(ma); //创建线程 ,其目标对象是ma
14 mydad.start(); //启动线程
15 mymom.start();
16 //主线程
17 for(int i=1 ;i<=20 ; i++)
18 System.out.print("me"+i+" ");
19
20 }
21 }
22
23 class baba implements Runnable //实现Runnable
24 {
25 public void run()
26 {
27 for(int i=1;i<=20;i++)
28 System.out.print(" dad"+i+" ");
29 }
30 }
31
32 class mom implements Runnable //实现Runnable
33 {
34 public void run()
35 {
36 for(int i=1; i<=20 ;i++)
37 System.out.print("Mon"+i+" ");
38 }
39 }
2 //主线程
3 public class Example12_2 {
4 public static void main(String [] args )
5 {
6 Thread mydad ; //用Thread声明线程
7 Thread mymom ;
8 baba ba ; //ba是目标对象
9 mom ma ;
10 ba = new baba(); //创建目标对象
11 ma = new mom();
12 mydad = new Thread(ba); //创建线程,其目标对象是bab
13 mymom = new Thread(ma); //创建线程 ,其目标对象是ma
14 mydad.start(); //启动线程
15 mymom.start();
16 //主线程
17 for(int i=1 ;i<=20 ; i++)
18 System.out.print("me"+i+" ");
19
20 }
21 }
22
23 class baba implements Runnable //实现Runnable
24 {
25 public void run()
26 {
27 for(int i=1;i<=20;i++)
28 System.out.print(" dad"+i+" ");
29 }
30 }
31
32 class mom implements Runnable //实现Runnable
33 {
34 public void run()
35 {
36 for(int i=1; i<=20 ;i++)
37 System.out.print("Mon"+i+" ");
38 }
39 }
本文链接:java之多线程(Thread),转载请注明。
没有评论:
发表评论