UITableView —QQ聊天实例
1.枚举:一组和数值有关的常量
1>定义枚举的两种方式
enum MessageType
{
MessageTypeSelf = 0 ,
MessageTypeOthe = 1
};
typedef enum {
MessageTypeSelf = 0 ,
MessageTypeOthe = 1
} MessageType;
2>枚举中的元素从0开始
3>使用枚举类型的成员变量
@property ( nonatomic , assign ) MessageType type;
2.获取屏幕的宽度
CGFloat screenW=[ UIScreen mainScreen ]. bounds . size . width ;
3.系统中的一个红,计算AB谁大,返回大的
MAX (A, B)
4.取消tableView的选中效果
self . tableView . allowsSelection = NO ;
5.去掉tableView的分割线 self . tableView . separatorStyle = UITableViewCellSeparatorStyleNone ;
6.RGB方式设置背景颜色
-全0的时候黑色 全1的时候白色
self . tableView . backgroundColor =[ UIColor colorWithRed : 240 / 255.0 green : 240 / 255.0 blue : 240 / 255.0 alpha : 1 ];
’
7.根据内容拉伸图片
UIImage * bgImage=[UIImage imageNamed:@"chat_send_nor"];
bgImage=[bgImage stretchableImageWithLeftCapWidth:bgImage.size.width/2 topCapHeight:bgImage.size.height/2];
1.stretchableImageWithLeftCapWidth 此方法内部调用了下面的方法
[bgImage stretchableImageWithLeftCapWidth:<#(NSInteger)#> topCapHeight:<#(NSInteger)#>]
2.平铺图片的方式改变图片大小,设置left为原图的一半,right自动计算宽度-left-1
[bgImage resizableImageWithCapInsets:<#(UIEdgeInsets)#>];
3.平铺方式改变图片大小
[bgImage resizableImageWithCapInsets:<#(UIEdgeInsets)#>]
8.改变键盘右下角的发送按钮
文本框的 Return Key属性
9.自动检测文本框是否输入值,没输入禁用发送按钮
Auto -entable Return Key 勾上
10.通知
通知中心
NSNotificationCenter *center=[ NSNotificationCenter defaultCenter ];
1>订阅通知 addObserver
参数
(id)observer 通知的订阅者
selector:(SEL)aSelector 收到通知之后执行的方法
name:(NSString *)aName 通知的名称
object:(id)anObject 通知的发布者
[center addObserver :p1 selector : @selector (fangfa:) name : @"通知名" object :c1];
-在要执行的方法里面有一个NSNotification参数,包含了通知名字,通知发布者和一些携带信息
-( void )fangfa:( NSNotification *) noti
{
NSLog ( @"通知名字%@" ,noti. name );
NSLog ( @"通知发布者%@" ,noti. object );
NSLog ( @"携带信息%@" ,noti. userInfo );
}
2>发布通知 postNotificationName
参数
(NSString *)aName 通知的名称
object:(id)anObject 通知的发布者
userInfo:(NSDictionary *)aUserInfo 发布通知的时候携带的参数
[center postNotificationName : @"通知名" object :c1 userInfo : @{ @"count" : @2} ];
3>移除通知 removeObserver:self
[[ NSNotificationCenter defaultCenter ] removeObserver : self ];
-有订阅就一定要有移除,否则会发生野指针错误
通知:多对多(1个对象可以通知多个对象,1个对象可以订阅多个对象发布的通知)
1.枚举:一组和数值有关的常量
1>定义枚举的两种方式
enum MessageType
{
MessageTypeSelf = 0 ,
MessageTypeOthe = 1
};
typedef enum {
MessageTypeSelf = 0 ,
MessageTypeOthe = 1
} MessageType;
2>枚举中的元素从0开始
3>使用枚举类型的成员变量
@property ( nonatomic , assign ) MessageType type;
2.获取屏幕的宽度
CGFloat screenW=[ UIScreen mainScreen ]. bounds . size . width ;
3.系统中的一个红,计算AB谁大,返回大的
MAX (A, B)
4.取消tableView的选中效果
self . tableView . allowsSelection = NO ;
5.去掉tableView的分割线 self . tableView . separatorStyle = UITableViewCellSeparatorStyleNone ;
6.RGB方式设置背景颜色
-全0的时候黑色 全1的时候白色
self . tableView . backgroundColor =[ UIColor colorWithRed : 240 / 255.0 green : 240 / 255.0 blue : 240 / 255.0 alpha : 1 ];
’
7.根据内容拉伸图片
UIImage * bgImage=[UIImage imageNamed:@"chat_send_nor"];
bgImage=[bgImage stretchableImageWithLeftCapWidth:bgImage.size.width/2 topCapHeight:bgImage.size.height/2];
1.stretchableImageWithLeftCapWidth 此方法内部调用了下面的方法
[bgImage stretchableImageWithLeftCapWidth:<#(NSInteger)#> topCapHeight:<#(NSInteger)#>]
2.平铺图片的方式改变图片大小,设置left为原图的一半,right自动计算宽度-left-1
[bgImage resizableImageWithCapInsets:<#(UIEdgeInsets)#>];
3.平铺方式改变图片大小
[bgImage resizableImageWithCapInsets:<#(UIEdgeInsets)#>]
8.改变键盘右下角的发送按钮
文本框的 Return Key属性
9.自动检测文本框是否输入值,没输入禁用发送按钮
Auto -entable Return Key 勾上
10.通知
通知中心
NSNotificationCenter *center=[ NSNotificationCenter defaultCenter ];
1>订阅通知 addObserver
参数
(id)observer 通知的订阅者
selector:(SEL)aSelector 收到通知之后执行的方法
name:(NSString *)aName 通知的名称
object:(id)anObject 通知的发布者
[center addObserver :p1 selector : @selector (fangfa:) name : @"通知名" object :c1];
-在要执行的方法里面有一个NSNotification参数,包含了通知名字,通知发布者和一些携带信息
-( void )fangfa:( NSNotification *) noti
{
NSLog ( @"通知名字%@" ,noti. name );
NSLog ( @"通知发布者%@" ,noti. object );
NSLog ( @"携带信息%@" ,noti. userInfo );
}
2>发布通知 postNotificationName
参数
(NSString *)aName 通知的名称
object:(id)anObject 通知的发布者
userInfo:(NSDictionary *)aUserInfo 发布通知的时候携带的参数
[center postNotificationName : @"通知名" object :c1 userInfo : @{ @"count" : @2} ];
3>移除通知 removeObserver:self
[[ NSNotificationCenter defaultCenter ] removeObserver : self ];
-有订阅就一定要有移除,否则会发生野指针错误
11.通知和代理的区别
1>相同点代理和通知都能完成对象之间的通信 (A对象告诉B对象发生了什么,A对象传递数据给B对象)
2>不同点
代理:1对1(1个对象,只能告诉另一个对象发生了什么)通知:多对多(1个对象可以通知多个对象,1个对象可以订阅多个对象发布的通知)