UITableview

//这里只罗列了部分属性,方法请参考官方SDK
#pragma mark  UITableViewCell
/**  UITableViewStyle 只读属性,初始化时设置*/
@property (nonatomic, readonly) UITableViewStyle style;
typedef NS_ENUM(NSInteger, UITableViewStyle) {
    UITableViewStylePlain,          // regular table view
    UITableViewStyleGrouped         // preferences style table view
};

/**  分割线 */
typedef NS_ENUM(NSInteger, UITableViewCellSeparatorStyle) {
    UITableViewCellSeparatorStyleNone,              // 没有分隔线
    UITableViewCellSeparatorStyleSingleLine,        // 默认
    UITableViewCellSeparatorStyleSingleLineEtched   // 只适用于分组模式
};

/**  选中效果 */
typedef NS_ENUM(NSInteger, UITableViewCellSelectionStyle) {
    UITableViewCellSelectionStyleNone,
    UITableViewCellSelectionStyleBlue,
    UITableViewCellSelectionStyleGray,
    UITableViewCellSelectionStyleDefault
};

/**  UITableViewCellSeparatorStyle */
@property (nonatomic) UITableViewCellSeparatorStyle separatorStyle;
/**  数据源 */
@property (nonatomic, weak, nullable) id <UITableViewDataSource> dataSource;
/**  代理 */
@property (nonatomic, weak, nullable) id <UITableViewDelegate> delegate;
/**  cell的高度 */
@property (nonatomic) CGFloat rowHeight;
/**  分区头部View的高度 */
@property (nonatomic) CGFloat sectionHeaderHeight;
/**  分区尾部View的高度 */
@property (nonatomic) CGFloat sectionFooterHeight;
/**  预估一个cell的高度 */
@property (nonatomic) CGFloat estimatedRowHeight                // 默认是0
/**  预估头部View的高度 */
@property (nonatomic) CGFloat estimatedSectionHeaderHeight      // 默认是0
/**  预估尾部View的高度 */
@property (nonatomic) CGFloat estimatedSectionFooterHeight      // 默认是0
/**  背景View */
@property (nonatomic, strong, nullable) UIView *backgroundView
/**  cell的分割线 默认左边少15个像素*/
@property (nonatomic) UIEdgeInsets separatorInset
/**  iOS8下需这样设置 */
-(void)viewDidLayoutSubviews
{
    if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
    [self.tableView setSeparatorInset:UIEdgeInsetsZero];
    }
    if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) {
        [self.tableView setLayoutMargins:UIEdgeInsetsZero];
    }
}


#pragma mark 编辑
/**  是否可编辑 */
@property (nonatomic, getter=isEditing) BOOL editing;               // 默认 NO.
/**  非编辑模式下是否可以选择 */
@property (nonatomic) BOOL allowsSelection;                         // 默认 YES.
/**  编辑模式下是否可以选择 */
@property (nonatomic) BOOL allowsSelectionDuringEditing;            // 默认 NO.
/**  非编辑模式下是否可以多选 */
@property (nonatomic) BOOL allowsMultipleSelection;                 // 默认 NO.
/**  编辑模式下是否可以选择 */
@property (nonatomic) BOOL allowsMultipleSelectionDuringEditing;    // 默认 NO.



#pragma mark 外观
/**  右侧分区索引的个数 */
@property (nonatomic) NSInteger sectionIndexMinimumDisplayRowCount;
/**  右侧分区索引的颜色 */
@property (nonatomic, strong, nullable) UIColor *sectionIndexColor;
/**  右侧分区索引的背景色 */
@property (nonatomic, strong, nullable) UIColor *sectionIndexBackgroundColor;
/**  右侧分区索引正在触摸时的背景色 */
@property (nonatomic, strong, nullable) UIColor *sectionIndexTrackingBackgroundColor;
/**  分割线颜色 */
@property (nonatomic, strong, nullable) UIColor *separatorColor;
/**  tabelView的头部View */
@property (nonatomic, strong, nullable) UIView *tableHeaderView;
/**  tabelView的尾部View */
@property (nonatomic, strong, nullable) UIView *tableFooterView;


#pragma mark UIScrollView
@property(nonatomic)         CGPoint                      contentOffset;                  // default CGPointZero
@property(nonatomic)         CGSize                       contentSize;                    // default CGSizeZero
@property(nonatomic)         UIEdgeInsets                 contentInset;                   // default UIEdgeInsetsZero.
@property(nullable,nonatomic,weak) id<UIScrollViewDelegate>        delegate;              // default nil.
@property(nonatomic,getter=isPagingEnabled) BOOL          pagingEnabled;                  // default NO.
@property(nonatomic,getter=isScrollEnabled) BOOL          scrollEnabled;                  // default YES.
@property(nonatomic)         BOOL                         showsHorizontalScrollIndicator; // default YES.
@property(nonatomic)         BOOL                         showsVerticalScrollIndicator;   // default YES.
@property(nonatomic,getter=isDirectionalLockEnabled) BOOL directionalLockEnabled;         // default NO.
@property(nonatomic)         BOOL                         bounces;                        // default YES.
@property(nonatomic)         BOOL                         alwaysBounceVertical;           // default NO.
@property(nonatomic)         BOOL                         alwaysBounceHorizontal;         // default NO.
@property(nonatomic)         UIEdgeInsets                 scrollIndicatorInsets;          // default UIEdgeInsetsZero.
@property(nonatomic)         UIScrollViewIndicatorStyle   indicatorStyle;
@property(nonatomic)         CGFloat                      decelerationRate;
@property(nonatomic,readonly,getter=isTracking)     BOOL tracking;        // returns YES
@property(nonatomic,readonly,getter=isDragging)     BOOL dragging;        // returns YES
@property(nonatomic,readonly,getter=isDecelerating) BOOL decelerating;    // returns YES


#pragma mark UITableViewHeaderFooterView
@property (nonatomic, strong, null_resettable) UIColor *tintColor;
@property (nonatomic, readonly, strong, nullable) UILabel *textLabel;
@property (nonatomic, readonly, strong, nullable) UILabel *detailTextLabel; // 只适用于头部分组模式
@property (nonatomic, readonly, strong) UIView *contentView;
@property (nonatomic, strong, nullable) UIView *backgroundView;
@property (nonatomic, readonly, copy, nullable) NSString *reuseIdentifier;


#pragma mark 方法
/**  cell 缩进等级 */
-(NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
        return 10;
    }
    return 0;
}


// cell.accessoryType =  UITableViewCellAccessoryDetailDisclosureButton
// 这个是在cell 的右侧添加个button 来展示或触发其他的展示消失或推送! 但是这个是系统的button 大多数的应用都是自己定义的button我下说下系统的吧
// 这个时候我们需要另个一个delegate 和触发cell 的函数是不同的
-(void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{
    NSString *titileString = [NSString stringWithFormat:@"你点击了按钮%@",[array objectAtIndex:[indexPath row]]];
    UIAlertView *alert = [[ UIAlertView alloc]initWithTitle:@"提示" message:titileString delegate:self    cancelButtonTitle:@"OK"otherButtonTitles: nil];
    [alert show];
}


// cell.accessoryView = mybutton
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    mybutton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    mybutton.frame = CGRectMake(0, 0, 100, 25);
    [mybutton setTitle:@"myButton" forState:UIControlStateNormal];
    [mybutton setBackgroundImage:[UIImage imageNamed:@"message"] forState:UIControlStateNormal];
    [mybutton addTarget:self action:@selector(myBtnClick:event:) forControlEvents:UIControlEventTouchUpInside];
    cell.accessoryView = mybutton;
}
-(void)myBtnClick:(id)sender event:(id)event
{
    
    NSSet *touches = [event allTouches];   // 把触摸的事件放到集合里
    UITouch *touch = [touches anyObject];   //把事件放到触摸的对象了
    CGPoint currentTouchPosition = [touch locationInView:self.tableview]; //把触发的这个点转成二位坐标
    NSIndexPath *indexPath = [self.tableview indexPathForRowAtPoint:currentTouchPosition]; //匹配坐标点
    if(indexPath !=nil){
        // 事件处理
        [self tableView:self.tableview accessoryButtonTappedForRowWithIndexPath:indexPath];
    }
}


// cell 删除
-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return UITableViewCellEditingStyleDelete;
}

/*改变删除按钮的title*/
-(NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return @"删除";
}

/*删除用到的函数*/
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle ==UITableViewCellEditingStyleDelete)
    {
        [self.arrayValueremoveObjectAtIndex:[indexPathrow]];  //删除数组里的数据
        [tableviewdeleteRowsAtIndexPaths:[NSMutableArrayarrayWithObject:indexPath]withRowAnimation:UITableViewRowAnimationAutomatic];  //删除对应数据的cell
    }
}



// 长按显示Menu菜单
-(BOOL)tableView:(UITableView *)tableView shouldShowMenuForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return   YES;
}


http://blog.csdn.net/lengshengren/article/category/1589965 这里有更为详细的使用方法
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值