国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

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

2019-11-14 20:10:08
字體:
來源:轉載
供稿:網友

最近要做一個項目,有個賬戶設置界面,看了微博、微信、QQ,他們的賬號設置都比較原生態沒做什么處理。春雨醫生的賬號不錯,做了許多處理。不說廢話直接上代碼。

第一步:

//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、設計好了這些東西后,開始進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//返回有幾個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 = [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、運行效果:

 

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


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 玉溪市| 海阳市| 喜德县| 如东县| 章丘市| 元氏县| 西华县| 阿坝| 临海市| 边坝县| 台前县| 阳山县| 萨嘎县| 湾仔区| 武清区| 定襄县| 黑龙江省| 金坛市| 凌源市| 孟村| 志丹县| 德格县| 平舆县| 蓝田县| 东兰县| 清徐县| 新竹市| 上饶县| 长海县| 班戈县| 达孜县| 麦盖提县| 临朐县| 濉溪县| 芜湖县| 陈巴尔虎旗| 海晏县| 璧山县| 东台市| 昌宁县| 宜春市|