麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

IOS開發(fā)之TableView、多個(gè)TableViewCell、自定義Cell、Cell上畫畫(故事板+代碼方式)

2019-11-14 20:10:08
字體:
供稿:網(wǎng)友

最近要做一個(gè)項(xiàng)目,有個(gè)賬戶設(shè)置界面,看了微博、微信、QQ,他們的賬號(hào)設(shè)置都比較原生態(tài)沒做什么處理。春雨醫(yī)生的賬號(hào)不錯(cuò),做了許多處理。不說廢話直接上代碼。

第一步:

//UserTableViewCell.h這里定義第一種Cell#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

故事板里的TableView和Cell的class和Cell的Identifier就不說了

例:

 

 

2、設(shè)計(jì)好了這些東西后,開始進(jìn)TableViewController里了:

//UserTableViewController.h#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 = [bundle pathForResource:@"UserViewCell" ofType:@"plist"];    self.UserViewCellDic = [[NSDictionary alloc]initWithContentsOfFile:plistpath];    self.listGroupname = [self.UserViewCellDic allKeys];      self.listGroupname = [self.listGroupname sortedArrayUsingSelector:@selector(compare:)];//排序}- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView//返回有幾個(gè)Section{    return [self.listGroupname count];}- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section//Section頭名字設(shè)為空{(diào)        NSString *groupName = @" ";    return groupName;}- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section//每個(gè)section的行數(shù){        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 = [indexPath section];    NSUInteger row = [indexPath 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 = [imagePath stringByAppendingString:@".png"];        cell.userviewcell2image.image = [UIImage imageNamed:imagePath];        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 = [UIColor colorWithRed:43/255.0f green:43/255.0f blue:233/255.0f alpha:1];        leftview.backgroundColor = [UIColor colorWithRed:43/255.0f green:43/255.0f blue:233/255.0f alpha:1];        rightview.backgroundColor = [UIColor colorWithRed:43/255.0f green:43/255.0f blue:233/255.0f alpha:1];        [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 = [imagePath stringByAppendingString:@".png"];        cell.userviewcellicon.image = [UIImage imageNamed:imagePath];        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;//最后的箭頭        //畫線        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 39, 320, 1)];        UIView *leftview = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 3, 40)];        UIView *rightview = [[UIView alloc]initWithFrame:CGRectMake(317, 0, 3, 40)];        view.backgroundColor = [UIColor colorWithRed:43/255.0f green:43/255.0f blue:233/255.0f alpha:1];        //alpha是透明度        leftview.backgroundColor = [UIColor colorWithRed:43/255.0f green:43/255.0f blue:233/255.0f alpha:0.3];        rightview.backgroundColor = [UIColor colorWithRed:43/255.0f green:43/255.0f blue:233/255.0f alpha:1];        [cell.contentView addSubview:view];        [cell.contentView addSubview:leftview];        [cell.contentView addSubview:rightview];         return cell;    }          }-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath//Cell的高度{    NSUInteger section = [indexPath section];    if (0 == section) {        return 80;    }else{        return 40;    }   }

這里附上Plist文件:

 

 

3、運(yùn)行效果:

 

寫的不是特別的詳細(xì),如果有什么不明白的或者需要源碼留郵箱!


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 日韩精品无码一区二区三区 | 双性精h调教灌尿打屁股的文案 | 欧美 日韩 国产 在线 | aaaaa国产欧美一区二区 | 91成人免费看 | 成人一级视频在线观看 | 99sesese| 成人免费观看av | 蝌蚪久久窝 | 成人在线视频免费观看 | 在线观看免费精品 | 黄色av电影在线播放 | 欧美日韩在线播放一区 | 久久久久久亚洲国产精品 | 久久蜜臀一区二区三区av | 欧美一级做一a做片性视频 日韩黄色片免费看 | 欧美一级在线免费 | 午夜视频中文字幕 | 久久毛片 | 99精品国产视频 | 美女啪网站 | 美女很黄很黄免费的 | 国产在线精品一区二区夜色 | 成人毛片网| 毛片视频免费观看 | 国产呻吟 | 国产在线观看91精品 | 欧美成人免费一级 | 日韩黄站| 国产免费网站视频 | 成人综合免费视频 | 男女羞羞视频在线免费观看 | 成人一区二区三区在线 | 99精品视频久久精品视频 | 免费毛片视频 | av国产免费 | 国产女厕一区二区三区在线视 | 国产精品自拍99 | 羞羞视频免费网站含羞草 | 成人小视频免费在线观看 | 欧美精品成人一区二区三区四区 |