5.UITableView使用 / 数据源 & 代理 / 行高 / TableViewCell 重用 / 索引栏
2016-03-23 11:14
423 查看
普通样式和分组样式有分组标签时 普通样式会在上方和下方标示出来分组样式不会显示只是在自己的组上下方有标示。
Accessory 有两个类型 accessorytype
accessoryView
在viewDidLoad中
Self.tableView.rowHeight = 80设置的是所有的cell
设置一个单元格要在UITableViewDelegate中设置
dataSource和delegate的区别
Datasource是在界面搭建之前
Delegate是在数据加载之后
Cell重用只会创建当前界面个数 + 1 //并不是绝对的
再次拖动会把前面出去的调用到后面
数据要放在外面
分割线是separator属性
Self.tableView.separatorInset uiedgeinsetsMake
修改它会修改图片文字和labeltext和detailtext之间的距离 但是右边不会根据他的改变而改变
启动图会影响进入手机时的屏幕样式
Imageviewtextlabeldetaitextlabelaccessoryaccessorytypebackgroundviewaccessoryview
Selectedbackgroundview
Detaitextlabel表格中小的描述内容
Accessory是附件
重用cell是从tableview中获取的(dequeue)
模型嵌套第二次是在set方法中执行
Sectionindextitle --- 侧边栏
Uitextfield *textfield
= [alert textfieldAtIndex:0];
Textfield.text = hero.name;
0代表获取到第一个行中,如果两个比如有password 如果是1则显示到password中
从网上获取要刷新全界面就要全局刷新
Uialertview
- (void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath{
// NSLog(@"%ld", (long)indexPath.row);
UIAlertView *alert = [[UIAlertViewalloc]initWithTitle:@"修改英雄"message:@"修改这个英雄名称"delegate:selfcancelButtonTitle:@"取消"otherButtonTitles:@"修改",nil];
alert.alertViewStyle =UIAlertViewStylePlainTextInput;
CZHero *hero =self.heroArray[indexPath.row];
self.indexPath= indexPath;
[alerttextFieldAtIndex:0].text = hero.name;
alert.delegate =self;
[alertshow];
}
- (void)alertView:(UIAlertView*)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex ==1) {
NSString *str =[alertViewtextFieldAtIndex:0].text;
CZHero *hero =self.heroArray[self.indexPath.row];
hero.name = str;
[self.tableViewreloadRowsAtIndexPaths:@[self.indexPath]withRowAnimation:UITableViewRowAnimationLeft];
}
}
23.Ios9方法
- (void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath{
UIAlertController *alert = [UIAlertControlleralertControllerWithTitle:@"My
alert"message:@"This isalert"preferredStyle:UIAlertControllerStyleAlert];
// UIAlertControllerStyleAlert
// UIAlertControllerStyleActionSheet从底部上来
[alertaddTextFieldWithConfigurationHandler:^(UITextField *_Nonnull textField)
{
CZHero *hero =self.heroArray[indexPath.row];
textField.text = hero.name;
}];
UIAlertAction *defaultAction = [UIAlertActionactionWithTitle:@"取消"style:UIAlertActionStyleCancelhandler:^(UIAlertAction
*_Nonnullaction) {
}];
UIAlertAction *xiuGAction = [UIAlertActionactionWithTitle:@"修改"style:UIAlertActionStyleDefaulthandler:^(UIAlertAction
*_Nonnullaction) {
CZHero *hero =self.heroArray[indexPath.row];
hero.name = alert.textFields[0].text;
[self.tableViewreloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationLeft];
}];
// UIAlertAction *goodAction = [UIAlertActionactionWithTitle:@"" style:<#(UIAlertActionStyle)#>handler:<#^(UIAlertAction * _Nonnull action)handler#>]
[alertaddAction:defaultAction];
[alertaddAction:xiuGAction];
[selfpresentViewController:alertanimated:YEScompletion:^{
nil;
}];
}
当删除数据的时候
,
他要判断cell的数量和数据的数量是否相同。
如果相同则删除
,
如果不同报错。
所以再删除方法之前要移除nsmutableView的相应数据。
Info.plist
放在文件夹中第一级目录中
Is initial view controller
第一个启动界面
uitableViewcontroller
当前界面只能是uitableView
uitableViewController
中的self.uiview
和 self.uitableView
内存地址相等
Xib
是一个数组
里边是你所定义的类型
Xib
的identity
要设置在属性检测器里。
Self.tableVeiew.tableheaderView = view.
只有高有用
Self.tableView.tableFooterView = view
只有高和x有用
上下不能共用一个uiview
否则下方不显示
tableViewCell ID标示要加static
放在对象区
静态区就是在对象在用的时候存在而在对象销毁的时候销毁
转圈的要设置animal
才能转
Awakefromnib
加载完xib之后想对他做操作的时候可以使用
Kvc
可以自动进行类型转换,
前提是他能转。
@property(nonatomic, assign, getter = isVip) BOOL vip;
模型中的数据只能比plist多不能比他少
自定义cell
空间添加到contentcell中
CGRect bounds = [userName boundingRectWithSize-----]
Label
换行
lines
换行
self。Messagelabel.numberOfLines = 0
uitableViewController
全屏滑动
当发现项目中有启动图和appicon图标的时候先设置这两个在改变文件夹
当有多人聊天
可以定义枚举
自定义textField
先设置为无边框
再设置backgroundImage
当前时间是否隐藏
:
在字典转模型中判断,
mArray
中存在上一次的
而且转成功的是当前的进行对比
在原来模型中设置BOOL是否显示属性。
Self.hidden
输入完之后跳到最后一行
//4. 让talbView滚动到最后一行
// > 4.1 定义一个NSIndexPath
NSIndexPath *indexPath = [NSIndexPath
indexPathForRow:(self.messageArray.count-1)
inSection:0];
[self.tableView
scrollToRowAtIndexPath:indexPath
atScrollPosition:UITableViewScrollPositionBottom
animated:YES];
使用通知之后一定记得要移除通知
- (void)dealloc{
//通知移除
[[NSNotificationCenter
defaultCenter]removeObserver:self];
}
Nsdate
的使用
NSDate *date = [NSDatedate];
NSDateFormatter *dateFormate = [[NSDateFormatter
alloc] init];
dateFormate.dateFormat =
@"HH:mm";
NSString *dateStr = [dateFormate
stringFromDate:date];
textField
的监听return
的机制
- (BOOL)textFieldShouldReturn:(UITextField *)textField
裁剪图片
image = [image
resizableImageWithCapInsets:UIEdgeInsetsMake(image.size.height *
0.5, image.size.width *
0.5, image.size.height *
0.5, image.size.width *
0.5) resizingMode:UIImageResizingModeTile];
内部边距很重要
设置完边距要调整原来在frame中设置的宽高和x进行调整
self.messageBtn.titleEdgeInsets =
UIEdgeInsetsMake(20,
20,
20, 20);
通知
1. // WithName
第一个参数:name
代表通知的名称
// object :
代表发送通知的对象
// userInfo :代表附加信息
// [NSNotificationnotificationWithName:<#(nonnull NSString *)#> object:<#(nullableid)#> userInfo:<#(nullable NSDictionary *)#>]
2.
//监听者一定要在通知发布之前进行监听
//是用通知中心进行添加
// addObserver 第一个参数对象 ->哪个对象进行监听
// selector 第一个参数对象,监听到消息之后,触发什么方法
//
这个方法,要卸载对应的对象,它的类中,它是一个对象的方法,所以是一个实例方法
// name ->发布通知的名字
当把名字设置为Nil的时候,代表任何名字的通知都接收
// object ->发布的对象
当object设置为Nil的时候,代表接收任何对象的通知、
[notificationCenter addObserver:<#(nonnull id)#>selector:<#(nonnull SEL)#> name:<#(nullable NSString *)#>object:<#(nullable id)#>]
3.
//没有对象的时候发送通知
//这是发送通知的方法
// postNotificationName
发送通知的名字
// object 代表发送通知的对象
// userInfo 额外的信息
// [notificationCenterpostNotificationName:<#(nonnull NSString *)#> object:<#(nullableid)#> userInfo:<#(nullable NSDictionary *)#>]
Accessory 有两个类型 accessorytype
accessoryView
在viewDidLoad中
Self.tableView.rowHeight = 80设置的是所有的cell
设置一个单元格要在UITableViewDelegate中设置
dataSource和delegate的区别
Datasource是在界面搭建之前
Delegate是在数据加载之后
Cell重用只会创建当前界面个数 + 1 //并不是绝对的
再次拖动会把前面出去的调用到后面
数据要放在外面
分割线是separator属性
Self.tableView.separatorInset uiedgeinsetsMake
修改它会修改图片文字和labeltext和detailtext之间的距离 但是右边不会根据他的改变而改变
启动图会影响进入手机时的屏幕样式
Imageviewtextlabeldetaitextlabelaccessoryaccessorytypebackgroundviewaccessoryview
Selectedbackgroundview
Detaitextlabel表格中小的描述内容
Accessory是附件
重用cell是从tableview中获取的(dequeue)
模型嵌套第二次是在set方法中执行
Sectionindextitle --- 侧边栏
Uitextfield *textfield
= [alert textfieldAtIndex:0];
Textfield.text = hero.name;
0代表获取到第一个行中,如果两个比如有password 如果是1则显示到password中
从网上获取要刷新全界面就要全局刷新
Uialertview
- (void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath{
// NSLog(@"%ld", (long)indexPath.row);
UIAlertView *alert = [[UIAlertViewalloc]initWithTitle:@"修改英雄"message:@"修改这个英雄名称"delegate:selfcancelButtonTitle:@"取消"otherButtonTitles:@"修改",nil];
alert.alertViewStyle =UIAlertViewStylePlainTextInput;
CZHero *hero =self.heroArray[indexPath.row];
self.indexPath= indexPath;
[alerttextFieldAtIndex:0].text = hero.name;
alert.delegate =self;
[alertshow];
}
- (void)alertView:(UIAlertView*)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex ==1) {
NSString *str =[alertViewtextFieldAtIndex:0].text;
CZHero *hero =self.heroArray[self.indexPath.row];
hero.name = str;
[self.tableViewreloadRowsAtIndexPaths:@[self.indexPath]withRowAnimation:UITableViewRowAnimationLeft];
}
}
23.Ios9方法
- (void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath{
UIAlertController *alert = [UIAlertControlleralertControllerWithTitle:@"My
alert"message:@"This isalert"preferredStyle:UIAlertControllerStyleAlert];
// UIAlertControllerStyleAlert
// UIAlertControllerStyleActionSheet从底部上来
[alertaddTextFieldWithConfigurationHandler:^(UITextField *_Nonnull textField)
{
CZHero *hero =self.heroArray[indexPath.row];
textField.text = hero.name;
}];
UIAlertAction *defaultAction = [UIAlertActionactionWithTitle:@"取消"style:UIAlertActionStyleCancelhandler:^(UIAlertAction
*_Nonnullaction) {
}];
UIAlertAction *xiuGAction = [UIAlertActionactionWithTitle:@"修改"style:UIAlertActionStyleDefaulthandler:^(UIAlertAction
*_Nonnullaction) {
CZHero *hero =self.heroArray[indexPath.row];
hero.name = alert.textFields[0].text;
[self.tableViewreloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationLeft];
}];
// UIAlertAction *goodAction = [UIAlertActionactionWithTitle:@"" style:<#(UIAlertActionStyle)#>handler:<#^(UIAlertAction * _Nonnull action)handler#>]
[alertaddAction:defaultAction];
[alertaddAction:xiuGAction];
[selfpresentViewController:alertanimated:YEScompletion:^{
nil;
}];
}
当删除数据的时候
,
他要判断cell的数量和数据的数量是否相同。
如果相同则删除
,
如果不同报错。
所以再删除方法之前要移除nsmutableView的相应数据。
Info.plist
放在文件夹中第一级目录中
Is initial view controller
第一个启动界面
uitableViewcontroller
当前界面只能是uitableView
uitableViewController
中的self.uiview
和 self.uitableView
内存地址相等
Xib
是一个数组
里边是你所定义的类型
Xib
的identity
要设置在属性检测器里。
Self.tableVeiew.tableheaderView = view.
只有高有用
Self.tableView.tableFooterView = view
只有高和x有用
上下不能共用一个uiview
否则下方不显示
tableViewCell ID标示要加static
放在对象区
静态区就是在对象在用的时候存在而在对象销毁的时候销毁
转圈的要设置animal
才能转
Awakefromnib
加载完xib之后想对他做操作的时候可以使用
Kvc
可以自动进行类型转换,
前提是他能转。
@property(nonatomic, assign, getter = isVip) BOOL vip;
模型中的数据只能比plist多不能比他少
自定义cell
空间添加到contentcell中
CGRect bounds = [userName boundingRectWithSize-----]
Label
换行
lines
换行
self。Messagelabel.numberOfLines = 0
uitableViewController
全屏滑动
当发现项目中有启动图和appicon图标的时候先设置这两个在改变文件夹
当有多人聊天
可以定义枚举
自定义textField
先设置为无边框
再设置backgroundImage
当前时间是否隐藏
:
在字典转模型中判断,
mArray
中存在上一次的
而且转成功的是当前的进行对比
在原来模型中设置BOOL是否显示属性。
Self.hidden
输入完之后跳到最后一行
//4. 让talbView滚动到最后一行
// > 4.1 定义一个NSIndexPath
NSIndexPath *indexPath = [NSIndexPath
indexPathForRow:(self.messageArray.count-1)
inSection:0];
[self.tableView
scrollToRowAtIndexPath:indexPath
atScrollPosition:UITableViewScrollPositionBottom
animated:YES];
使用通知之后一定记得要移除通知
- (void)dealloc{
//通知移除
[[NSNotificationCenter
defaultCenter]removeObserver:self];
}
Nsdate
的使用
NSDate *date = [NSDatedate];
NSDateFormatter *dateFormate = [[NSDateFormatter
alloc] init];
dateFormate.dateFormat =
@"HH:mm";
NSString *dateStr = [dateFormate
stringFromDate:date];
textField
的监听return
的机制
- (BOOL)textFieldShouldReturn:(UITextField *)textField
裁剪图片
image = [image
resizableImageWithCapInsets:UIEdgeInsetsMake(image.size.height *
0.5, image.size.width *
0.5, image.size.height *
0.5, image.size.width *
0.5) resizingMode:UIImageResizingModeTile];
内部边距很重要
设置完边距要调整原来在frame中设置的宽高和x进行调整
self.messageBtn.titleEdgeInsets =
UIEdgeInsetsMake(20,
20,
20, 20);
通知
1. // WithName
第一个参数:name
代表通知的名称
// object :
代表发送通知的对象
// userInfo :代表附加信息
// [NSNotificationnotificationWithName:<#(nonnull NSString *)#> object:<#(nullableid)#> userInfo:<#(nullable NSDictionary *)#>]
2.
//监听者一定要在通知发布之前进行监听
//是用通知中心进行添加
// addObserver 第一个参数对象 ->哪个对象进行监听
// selector 第一个参数对象,监听到消息之后,触发什么方法
//
这个方法,要卸载对应的对象,它的类中,它是一个对象的方法,所以是一个实例方法
// name ->发布通知的名字
当把名字设置为Nil的时候,代表任何名字的通知都接收
// object ->发布的对象
当object设置为Nil的时候,代表接收任何对象的通知、
[notificationCenter addObserver:<#(nonnull id)#>selector:<#(nonnull SEL)#> name:<#(nullable NSString *)#>object:<#(nullable id)#>]
3.
//没有对象的时候发送通知
//这是发送通知的方法
// postNotificationName
发送通知的名字
// object 代表发送通知的对象
// userInfo 额外的信息
// [notificationCenterpostNotificationName:<#(nonnull NSString *)#> object:<#(nullableid)#> userInfo:<#(nullable NSDictionary *)#>]
相关文章推荐
- 4.ScrollView常用属性,常用代理方法,图片轮播器,UIAlertView/UIActionSheet
- Bctf-pwn_ruin-re_lastflower
- win8 &win10系统下Guest 帐号本地主机登录
- skcatSgnisueueuQtnemelpmI.232
- iOS开发——UIImageView
- UITableView分割线从边框顶端开始
- Android Activity.runOnUiThread() 和 Handler
- 【学渣笔记】Xitrum Scala Web Framework Guide
- iOS UITableCell复用
- UIImageView的ContentMode属性
- Process 'command '**/ndk-build.cmd'' finished with non-zero exit value 1
- UIView的layoutSubviews和drawRect
- (转)Storm UI 解释
- marquee标签弹幕效果
- iOS-添加UINavigation
- dispatchTouchEvent
- QtQuick项目部署
- Java中Integer的valueOf方法,-128到127的整数将被缓存
- 使用fuel部署openstack时遇到的问题记录一下
- Java序列化之transient和serialVersionUID的使用