iOS开发UI篇—UITableview控件使用小结一、UITableview的使用步骤UITableview的使用就只有简单的三个步骤:1.告诉一共有多少组数据方法:- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;2.告诉每组一共有多少行方法:- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section; 3.设置每组每行(cell)方法:- (UITableViewCell *)tableView:(UITableView *)tableView cell...
tableView 实现的方法 无分组的cell#pragma mark - Table view data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{return self.contacts.count;
}- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{// 1.创建cellMJContactCell *cell = [MJContactCell cellWithTableView:tableView];// 2.设置cell的数据cell.con...
思路: 1.new 一个 Empty 后缀为 .txt 文件,内容随笔拷贝一段 2.用 NSString 接收本地文件,再用一个标题拼接字符串 3.创建一个 NSMutableParagraphStyle 实例,设置标题居中、标题距离正文间隔 4.创建一个 NSMutableParagraphStyle 实例,设置正文左对齐、每段开头缩进 10 5.创建一个基础动画的实例,用代理监听动画结束话不多说上代码#pragma mark -- 拼接字符
- (void)loadData:(NSString *)filename {//第一个...
*****HMViewController#import"HMViewController.h"#import"HMStatus.h"#import"HMStatusCell.h"#import"HMStatusFrame.h"@interface HMViewController ()
/** 保存statusFrame模型的数组 */
@property (nonatomic, strong) NSArray *statusFrames;
@end@implementation HMViewController- (NSArray *)statusFrames
{if (_statusFrames == nil) _statusFrames = [HMStatusFrame statusFrames];return _statusFrames;
}- (void)view...
UITableView相当于Android里面的ListView,但功能却比ListView强大太多。使用UITableView需要指定数据源和代理。1.显示所有的行遵守UITableViewDataSource协议,必须实现的方法有两个:// 每一节里面有多少行
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
// 每行的View,这里是UITableViewCell
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger...
效果:这里的数据模型有两层:每一组汽车是一层模型,每一组里面的每一行汽车品牌也是一层模型。(1)我们先创建一个WSCars模型。 在WSCars.h中:#import <Foundation/Foundation.h>@interface WSCars : NSObject
@property(nonatomic,copy) NSString *icon;
@property(nonatomic,copy) NSString *name;+(WSCars *)carsWithDict:(NSDictionary *)dict;
-(WSCars *)initWithDict:(NSDictionary *)dict;
@end
在WSCars.m中:
#import...
?123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110#import "MainViewController.h" @interfaceMainViewController () @end @implementationMainViewController #pragma mark 实例化视图- (void)loadView{ self.tableView = [[UITableView ...
1. 初始化NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:@"YOUR_STRING"];还有一种初始化方法,直接在初始化时给String赋属性值:- (instancetype)initWithString:(NSString *)str attributes:(nullable NSDictionary<NSString *, id> *)attrs; 2. 给String赋属性值例如,把前4位字符字体颜色改为红色:[attributedString addAttribute:NSForegroundColorAttributeName ...
//添加手势,点击屏幕其他区域关闭键盘操作UITapGestureRecognizer *gesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(SEL)];gesture.numberOfTapsRequired = 1;gesture.delegate = self;[self.view addGestureRecognizer:gesture];
#pragma mark - UIGestureRecognizerDelegate
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{// 若...
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{ cell.separatorInset = UIEdgeInsetsZero; cell.layoutMargins = UIEdgeInsetsZero; cell.preservesSuperviewLayoutMargins = NO;}原文:http://www.cnblogs.com/niit-soft-518/p/7404941.html
1int main(int argc, constchar * argv[]) {2 @autoreleasepool {3 Person *p1 = [[Person alloc] initWithName:@"张三"];4 Person *p2 = [[Person alloc] initWithName:@"李四"];5 Person *p3 = [[Person alloc] initWithName:@"王五"];6//3创建一个数组 7 NSArray *array = [[NSArray alloc] initWithObjects:p1,p2,p3, nil];8 NSMutableArray *arraym = [[NSMutableArray alloc] i...
Model 类:@interface ListModel : NSObject@property (nonatomic, copy)NSString *time;
@property (nonatomic, copy)NSString *cname;
@property (nonatomic, copy)NSString *summary;
@property (nonatomic, copy)NSString *title;
@property (nonatomic, copy)NSString *type;- (void)createArray:(NSDictionary *)resultdataSource:(NSMutableArray *)dataSource;VC:#import"ViewController.h"#import"ListModel.h"#import"D...
在他们的定义UItableView什么时候,选择当style至Group时间,后常透明切割线依然,去除。只有再次刷新了BackgroundView它可以覆盖原来的 //取消切割线 UIView *view= [ [ [ UIView
alloc ] init ] autorelease]; [cell setBackgroundView :view]; //取消点击效果 cell.selectionStyle =
UITableViewCellSelectionStyleNone;版权声明:本文博客原创文章。博客,未经同意,不得转载。原文:http://www.cnblogs.com/h...
iOS中表格(UITableView)嵌套表格的简单实现首先说一下思路:我们在一个控制器里面定义2个tableview,一个作为被嵌套的rootTable,一个作为嵌套的表格tableView1,那我们要实现UITableViewDelegate,UITableViewDataSource,的代理的时候,该怎么区分呢?其实很简单,有两种方法,一个是给定义的2个tableview设置tag值,另一个是直接写出来tableView== rootTable时实现他得代理,否则就实现tableView1的代理方法。测试环境 Xcode6.1
Dem...
-(NSArray<UITableViewRowAction*>*)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
{UITableViewRowAction *rowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefaulttitle:@"删除"handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {NSLog(@"删除");}];UITableViewRowAction *rowActionSec = [UITableViewRowA...