uitableview

你真的了解UITableViewCell重用吗?

徘徊边缘 提交于 2020-02-29 16:41:03
一:首先查看一下关于UITableViewCell 重用的定义 - (nullable __kindof UITableViewCell *)dequeueReusableCellWithIdentifier:(NSString *)identifier; - (__kindof UITableViewCell *)dequeueReusableCellWithIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(6_0); 在tableview 新建的时候, 会新建一个复用池(reuse pool). 这个复用池可能是一个队列, 或者是一个链表, 保存着当前的Cell.pool 中的对象的复用标识符就是reuseIdentifier, 标识着不同的种类的cell. 所以调用dequeueReusableCellWithIdentifier: 方法获取cell. 从pool 中取出来的cell 都是tableview 展示的原型. 无论之前有什么状态, 全部都要设置一遍. 在 UITableView创建同时 ,会创建一个空的复用池 .之后 UITableView在内部维护这个复用池 .一般情况下 ,有两种用法 ,一种是在取出一个空的 cell的时候再新建一个

uitableview 的可编辑性小结

浪子不回头ぞ 提交于 2020-02-29 06:03:33
在让tableview可编辑时,添加实现下面3个delegate方法: - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{ return YES; } - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{ return UITableViewCellEditingStyleDelete; } // 添加这个方法后可以滑动cell,显示delete, ps: editingStyleForRowAtIndexPath 为 UITableViewCellEditingStyleInsert 的时候滑动无效, 需要自行添加[tbView_roster setEditing:YES animated:YES]; 例如下面在 didSelectRowAtIndexPath 中添加 setEditing:animated: - (void) tableView:(UITableView *)tableView commitEditingStyle:

UITableView的简单的使用

风流意气都作罢 提交于 2020-02-29 06:00:24
@interface TableListViewController : UITableViewController @end @implementation TableListViewController //表格可以以分段或者以单个列表的形式显示其数据。对于简单的表格,返回1,表示整个表格应该作为一个列表显示。在分段列表中,返回2及以上的值。 - (NSInteger)numberOfSectionsInTableView:(UITableView *)aTableView { return 1; } //第二个调用,此方法返回每个分段的行数,处理简单列表时,返回整个表格的行数。 - (NSInteger)tableView:(UITableView *)aTableView numberOfRowsInSection:(NSInteger)section { NSLog(@"[UIFont familyNames].count,%d",[UIFont familyNames].count); return [UIFont familyNames].count; } //第三个调用,返回某一个item - (UITableViewCell *)tableView:(UITableView *)tView cellForRowAtIndexPath:(NSIndexPath *

How to remove UITableView section header separator

跟風遠走 提交于 2020-02-28 01:27:27
问题 I would like to remove (or make them clearColor) UITableView's section header separators. Setting tableView.separatorStyle = .none doesn't work. I've also tried solutions from here, but none of them actually worked for me (maybe because the answers are pretty old). I still get this tiny separator below the section header. I created the UITableView in Storyboard and add a UITableViewCell there. Then I set it as a header like this: func tableView(_ tableView: UITableView, viewForHeaderInSection

How do I work with realm notification if result is updated after notification is initialized?

安稳与你 提交于 2020-02-27 13:00:09
问题 I use a UITableView with Realm results as it's data source. The results are registered with a realm notification and is updated very well when changes occur. However, the same table view has a search bar that filters the result based on the users search query. This also works fine, but if the notification listener recognizes an update, the section and row count does not match. What is the correct way to do this? Is it possible to update the NotificationToken? This is the code that initializes

How do I work with realm notification if result is updated after notification is initialized?

空扰寡人 提交于 2020-02-27 12:59:25
问题 I use a UITableView with Realm results as it's data source. The results are registered with a realm notification and is updated very well when changes occur. However, the same table view has a search bar that filters the result based on the users search query. This also works fine, but if the notification listener recognizes an update, the section and row count does not match. What is the correct way to do this? Is it possible to update the NotificationToken? This is the code that initializes

iOS cell手势左滑、右滑

僤鯓⒐⒋嵵緔 提交于 2020-02-27 08:50:51
MGSwipeTableCell - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString * reuseIdentifier = @"programmaticCell"; MGSwipeTableCell * cell = [self.tableView dequeueReusableCellWithIdentifier:reuseIdentifier]; if (!cell) { cell = [[MGSwipeTableCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuseIdentifier]; } cell.textLabel.text = @"Title"; cell.detailTextLabel.text = @"Detail text"; cell.delegate = self; //optional //configure left buttons cell.leftButtons = @[[MGSwipeButton buttonWithTitle:@"" icon:

选中后,可以在UITableViewCell上设置高度变化的动画吗?

最后都变了- 提交于 2020-02-27 06:15:35
我在iPhone应用程序中使用的是 UITableView ,并且有一个属于一组的人的列表。 我希望这样,以便当用户单击特定的人(从而选择单元格)时,单元格的高度会增加,以显示多个用于编辑该人的属性的UI控件。 这可能吗? #1楼 我只是通过一点技巧解决了这个问题: static int s_CellHeight = 30; static int s_CellHeightEditing = 60; - (void)onTimer { cellHeight++; [tableView reloadData]; if (cellHeight < s_CellHeightEditing) heightAnimationTimer = [[NSTimer scheduledTimerWithTimeInterval:0.001 target:self selector:@selector(onTimer) userInfo:nil repeats:NO] retain]; } - (CGFloat)tableView:(UITableView *)_tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { if (isInEdit) { return cellHeight; } cellHeight = s

UITableView-滚动到顶部

蓝咒 提交于 2020-02-27 04:34:48
在表格视图中,我必须滚动到顶部。 但是我不能保证第一个对象将是第0节,第0行。可能是我的表视图将从第5节开始。 所以当我打电话时我得到一个例外: [mainTableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:NO]; 还有另一种滚动到表格视图顶部的方法吗? #1楼 此代码让您将特定部分滚动到顶部 CGRect cellRect = [tableinstance rectForSection:section]; CGPoint origin = [tableinstacne convertPoint:cellRect.origin fromView:<tableistance>]; [tableinstance setContentOffset:CGPointMake(0, origin.y)]; #2楼 最好不要使用NSIndexPath(空表),也不要假设最高点是CGPointZero(内容插入),这就是我所使用的- [tableView setContentOffset:CGPointMake(0.0f, -tableView.contentInset.top)

iOS UITableViewCell滑动删除

大兔子大兔子 提交于 2020-02-27 04:26:51
首先,我们初始化一个界面,以列表的形式展示 1 2 3 4 5 6 7 8 9 10 11 #pragma mark - 初始化UI - ( void )initUI{ self .view.backgroundColor = RGB(242, 242, 247); self .automaticallyAdjustsScrollViewInsets = NO ; sideslipTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 60, kScreenWidth, kScreenHeight - 60) style:UITableViewStylePlain]; sideslipTableView.backgroundColor = [UIColor clearColor]; sideslipTableView.delegate = self ; sideslipTableView.dataSource = self ; sideslipTableView.separatorStyle = UITableViewCellSeparatorStyleNone; [ self .view addSubview:sideslipTableView]; } 然后,准备数据源 1 2 3 4 5 6 7 8 9 10