ios进阶iOS学习笔记iOS即时通讯

iOS -- Cell功能列表

2015-11-12  本文已影响2521人  iOS_成才录

1、cell的分割线 与 左右间距设置

2、cell点击弹出menu菜单

Snip20151027_5.png
方案一:
方案二:自己给Cell添加UIMenuController功能
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    // 取出cell
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    
    UIMenuController *menu = [UIMenuController sharedMenuController];
    
    // 设置菜单内容
    menu.menuItems = @[
                       [[UIMenuItem alloc] initWithTitle:@"顶" action:@selector(ding:)],
                       [[UIMenuItem alloc] initWithTitle:@"回复" action:@selector(reply:)],
                       [[UIMenuItem alloc] initWithTitle:@"举报" action:@selector(warn:)]
                       ];
    
    // 显示位置 : 参考Cell的左上角,指向Cell中间的一条高1的位置
   /*
     targetRect:menuController指向的矩形框
     targetView:targetRect以targetView的左上角为坐标原点
     */
    CGRect rect = CGRectMake(0, cell.height * 0.5, cell.width, 1);
    [menu setTargetRect:rect inView:cell];
    
    // 显示出来
    [menu setMenuVisible:YES animated:YES];
}
Snip20151028_14.png
#pragma mark - UIMenuController处理
- (BOOL)canBecomeFirstResponder
{
    return YES;
}

- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
    if (!self.isFirstResponder) { // 文本框弹出键盘, 文本框才是第一响应者
        if (action == @selector(ding:)
            || action == @selector(reply:)
            || action == @selector(warn:)) return NO;
    }
    
    return [super canPerformAction:action withSender:sender];
}

- (void)ding:(UIMenuController *)menu
{
    JPLog(@"ding - %@ %@",
           self.selectedComment.user.username,
           self.selectedComment.content);
}

- (void)reply:(UIMenuController *)menu
{
    JPLog(@"reply - %@ %@",
           self.selectedComment.user.username,
           self.selectedComment.content);
}

- (void)warn:(UIMenuController *)menu
{
    JPLog(@"warn - %@ %@",
           self.selectedComment.user.username,
           self.selectedComment.content);
}

3、自定义Cell不等高

3.1 思路分析:
3.2 实现方案
上一篇 下一篇

猜你喜欢

热点阅读