add cell ios
2013-12-02 10:47:32 u012980997 阅读数 631
Phone提供了4种基本的表格视图单元格,在SDK 3.0 之后,每个单元格都有3个属性textLabel,detailTextLabel和imageView。
下面一一介绍这4种基本格式:
1、UITableViewCellStyleDefault
该格式提供了一个简单的左对齐的文本标签textLabel和一个可选的图像imageView。如果显示图像,那么图像将在最左边。
这种格式虽然可以设置detailTextLabel,但是不会显示该标签。
2、UITableViewCellStyleSubtitle
该格式与前一种相比,增加了对detailTextLabel的支持,该标签将会显示在textLabel标签的下面,字体相对较小。
3、UITableViewCellStyleValue1
该格式居左显示textLabel,居右显示detailTextLabel,且字体较小。
4、UITableViewCellStyleValue2
该格式居左现实一个小型蓝色主标签textLabel,在其右边显示一个小型黑色副标题详细标签detailTextLabel。
该格式不支持图像
个人感觉,格式1和2使用较多,如果这两种不能满足我的要求,那么就采用定制UITableViewCell的方式。
2015-04-02 17:47:28 u013936522 阅读数 442

实现长按弹出菜单栏需要做3点:

1.在view(cell)或者viewController中调用-becomeFirstResponder方法;

2.你的view获得或者view controller需要实现 -canBecomeFirstResponder 方法,返回YES;

3.你的view获得或者view controller需要实现-canPerformAction:action withSender:sender 方法来隐藏或者现实响应的item;

cell中关键代码展示:

1.添加长安事件

[self addGestureRecognizer: [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longTap:)]];

2.处理长按事件

-(void)longTap:(UILongPressGestureRecognizer *)longRecognizer
{
if (longRecognizer.state==UIGestureRecognizerStateBegan) {
[self becomeFirstResponder];
UIMenuController *menu=[UIMenuController sharedMenuController];
UIMenuItem *copyItem = [[UIMenuItem alloc] initWithTitle:@"复制"action:@selector(copyItemClicked:)];
UIMenuItem *resendItem = [[UIMenuItem alloc] initWithTitle:@"转发"action:@selector(resendItemClicked:)];
[menu setMenuItems:[NSArray arrayWithObjects:copyItem,resendItem,nil]];
[menu setTargetRect:self.bounds inView:self];
[menu setMenuVisible:YES animated:YES];
}
}

3.实现默认方法

#pragma mark 处理action事件
-(BOOL)canPerformAction:(SEL)action withSender:(id)sender{
if(action ==@selector(copyItemClicked:)){
return YES;
}else if (action==@selector(resendItemClicked:)){
return YES;
}
return [super canPerformAction:action withSender:sender];
}
#pragma mark 实现成为第一响应者方法
-(BOOL)canBecomeFirstResponder{
return YES;
}

4.处理item点击事件

#pragma mark method
-(void)resendItemClicked:(id)sender{
NSLog(@"转发");
//通知代理
}
-(void)copyItemClicked:(id)sender{
NSLog(@"复制");
// 通知代理 
}





2018-05-23 10:48:00 weixin_34259232 阅读数 35

首先在显示cell的上面这样


 if ([LNYroleId integerValue]!=1) {

        if(indexPath.row==0) {

            cell.hidden=YES;

            [cellremoveFromSuperview];

        }

    }

然后

- (CGFloat)tableView:(UITableView*)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath {

    if([LNYroleIdintegerValue]!=1) {

        if(indexPath.row==0) {

           return0;

        }

    }

    return 50;

}

就OK了

2019-07-07 13:45:07 weixin_30577801 阅读数 6


 

//

//  DynamicHeightsViewController.h

//  DynamicHeights

//

//  Created by Matt Long on 9/22/09.

//  Copyright Skye Road Systems, Inc. 2009. All rights reserved.

//


#import <UIKit/UIKit.h>


@interface DynamicHeightsViewController : UIViewController {

    IBOutlet UITableView *dataTableView;

    

    NSMutableArray *items;

}


@end


 


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//

//  DynamicHeightsViewController.m

//  DynamicHeights

//

//  Created by Matt Long on 9/22/09.

//  Copyright Skye Road Systems, Inc. 2009. All rights reserved.

//


#import "DynamicHeightsViewController.h"


#define FONT_SIZE 14.0f

#define CELL_CONTENT_WIDTH 320.0f

#define CELL_CONTENT_MARGIN 10.0f


@implementation DynamicHeightsViewController


- (void)viewDidLoad {

    [superviewDidLoad];

    

    items = [[NSMutableArray alloc] init];

    [itemsaddObject:@"After two years in Washington, I often long for the realism and sincerity of Hollywood.\n\n\t\t-Fred Thompson, Speech before the Commonwealth Club of Californiaaaagdd阿黑哥是否规范的阿黑哥是否规范的阿黑哥是否规范的阿黑哥是否规范的阿黑哥是否规范的阿黑哥是否规范的阿黑哥是否ll"];

    [itemsaddObject:@"It is a profitable thing, if one is wise, to seem foolish.\n\n\t\t-Aeschylus (525 BC - 456 BC)"];

    [itemsaddObject:@"Bill Gates is a very rich man today... and do you want to know why? The answer is one word: versions.\n\n\t\t-Dave Barry"];

    [itemsaddObject:@"At the worst, a house unkept cannot be so distressing as a life unlived.\n\n\t\t-Dame Rose Macaulay (1881 - 1958)"];

    [itemsaddObject:@"It is curious that physical courage should be so common in the world and moral courage so rare.\n\n\t\t-Mark Twain (1835 - 1910)"];

    [itemsaddObject:@"The knowledge of the world is only to be acquired in the world, and not in a closet.\n\n\t\t-Lord Chesterfield (1694 - 1773), Letters to His Son, 1746, published 1774"];

    [itemsaddObject:@"What lies behind us and what lies before us are tiny matters compared to what lies within us.\n\n\t\t-Ralph Waldo Emerson (1803 - 1882), (attributed)"];

     

}


- (void)dealloc {

    [items release], items = nil;

    [super dealloc];

}


#pragma mark -

#pragma mark UITableView Delegaates


- (NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section

{

return [items count];

}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;

{

return1;

}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;

{

    NSString *text = [items objectAtIndex:[indexPath row]];

    

    CGSize constraint = CGSizeMake(CELL_CONTENT_WIDTH - (CELL_CONTENT_MARGIN * 2), 20000.0f);

    

    CGSize size = [text sizeWithFont:[UIFontsystemFontOfSize:FONT_SIZE] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];

    

    CGFloat height = MAX(size.height, 44.0f);

    

    return height + (CELL_CONTENT_MARGIN * 2);

}


- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

    UITableViewCell *cell;

    UILabel *label = nil;

    

    cell = [tv dequeueReusableCellWithIdentifier:@"Cell"];

    if (cell == nil)

    {

        cell = [[[UITableViewCellalloc] initWithFrame:CGRectZeroreuseIdentifier:@"Cell"] autorelease];

        

        label = [[UILabel alloc] initWithFrame:CGRectZero];

        [label setLineBreakMode:UILineBreakModeWordWrap];

        [label setMinimumFontSize:FONT_SIZE];

        [label setNumberOfLines:0];

        [label setFont:[UIFontsystemFontOfSize:FONT_SIZE]];

        [label setTag:1];

        

        [[label layer] setBorderWidth:2.0f];

        

        [[cell contentView] addSubview:label];

        

    }

    NSString *text = [items objectAtIndex:[indexPath row]];

    

    CGSize constraint = CGSizeMake(CELL_CONTENT_WIDTH - (CELL_CONTENT_MARGIN * 2), 20000.0f);

    

    CGSize size = [text sizeWithFont:[UIFontsystemFontOfSize:FONT_SIZE] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];

    

    if (!label)

        label = (UILabel*)[cell viewWithTag:1];

    

    [label setText:text];

    [label setFrame:CGRectMake(CELL_CONTENT_MARGIN, CELL_CONTENT_MARGIN, CELL_CONTENT_WIDTH - (CELL_CONTENT_MARGIN * 2), MAX(size.height, 44.0f))];

    

    return cell;


}

 

转载于:https://www.cnblogs.com/james1207/p/3341743.html

2017-01-24 22:16:49 ete8652 阅读数 240

http://www.jianshu.com/p/02ab2b74c451

tableView的Cell有重用机制,这样会有一个问题,当一个cell正在加载图片时,又去滑动页面,可能会出现cell的图片错误。
为了防止重复下载,我们要进行缓存,分为内存缓存和磁盘缓存。
cell向下滑动时,停止数据请求。
cell停止时,就继续下载。
创建一个请求字典,key是url,值是请求图片的请求。必要时就停止。
再创建一个全局的queue来管理图片请求。

iOS 滑动删除cell

阅读数 154

iOS Cell小动画

阅读数 3

iOS cell刷新数据

阅读数 1169

iOS cell自动换行

阅读数 9

iOS 获取cell

阅读数 38

没有更多推荐了,返回首页