uitableview

UITableViewCell

北慕城南 提交于 2020-04-07 01:19:48
属性: //设置右边的指示样式cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;//设置右边的指示控件 cell.accessoryView = [[UISwitch alloc] init];//设置cell的选中样式 cell.selectionStyle = UITableViewCellSelectionStyleNone;//设置背景色 cell.backgroundColor = [UIColor redColor];//设置背景viewUIView *bg = [[UIView alloc] init]; bg.backgroundColor = [UIColor blueColor]; cell.backgroundView = bg;//设置选中的背景view UIView *selectedBg = [[UIView alloc] init]; selectedBg.backgroundColor = [UIColor purpleColor]; cell.selectedBackgroundView = selectedBg; 性能优化:   思路:当滚动列表时,部分UITableViewCell会移出窗口

UITableView编辑

五迷三道 提交于 2020-03-31 06:42:43
UITableView 编辑步骤如下: 1.让TableView处于编辑状态 2.协议设定 2.1.确定Cell是否处于编辑状态 2.2.设定Cell的编辑样式(删除、添加) 2.3.编辑状态进⾏提交 注意: 编辑结束后,由于numberOfRowsInSection这个协议只在 tableview添加到⽗视图的时候⾛⼀次,⽽且table上的数据 都是由数组提供,因此,需要先将数组中的元素删除,然后 让table的协议重新⾛⼀遍进⾏重新赋值。 即:先修改数据源,再刷新table(使⽤reloadData⽅法) //每一个视图控制器都有一个编辑按钮,因为项目中编辑的应用场景非常多,所以系统预留了一个编辑按钮供我们使用 self.navigationItem.leftBarButtonItem = self.editButtonItem; #pragma mark -----删除、添加数据----- //1、让将要执行删除、添加操作的表视图处于编辑状态 - (void)setEditing:(BOOL)editing animated:(BOOL)animated { //先执行父类中的这个方法 [super setEditing:editing animated:animated]; //表视图执行此方法 [self.tableView setEditing:editing

iOS有关横向TableView的东西

那年仲夏 提交于 2020-03-28 23:09:52
之前看到Apple store里面有横向的tableview,当然也有可能是collectionview啦。 尤其是项目中只有一条那么需要横向滑动的东西,就没有必要使用庞大的collectionview了,点缀的使用一下横向的tableview反而更方便和灵活。当然此处大部分的情况可能是在父tableview的cell中使用个横向的tableview。 下面就简单的介绍一下,基于系统原生的UITableView封装横向tableview的要点。 我封装tableview的时候主要使用了一种比较流行的方法,tableview旋转-PI/2个单位的弧度(即逆时针旋转90度),cell旋转PI/2个单位弧度(即顺时针旋转90度)。这样的最终结果就是tableview成为了横向的。封装的过程中有一个地方比较难以理解的,就是横向的tableview的point问题,因为旋转,默认的是以tableview的中心点旋转,这样就造成了旋转后“看起来”的位置或者说Frame发生了改变,所以要修复这个因为旋转造成的“Frame偏差”。此处,你可以拿着你的手机,竖着放在一张竖着的A4纸上面,手机的左上角与A4纸左上角重合,意味着point为(0,0),然后你把手机逆时针旋转90度,看看有什么结果,结果应该是,手机左面突出了A4纸一部分,上面也距离纸的顶边一定的距离。那么这个距离是多少呢

(Swift) How to hide some sections in tableView when toggle switch is on?

人走茶凉 提交于 2020-03-26 03:26:11
问题 I have 5 tebleView sections, code is mostly the same for each of them. Main difference is in cell.labelCell.text : CellForRow method: let cell = tableView.dequeueReusableCell(withIdentifier: "ToggleTableViewCell", for: indexPath) as! ToggleTableViewCell cell.cellSwitch.setOn(false, animated: false) switch (indexPath.section, indexPath.row) { case (1,0): cell.labelCell.text = "Section 1" cell.callback = { [unowned self] check in UIView.transition(with: tableView, duration: 0.5, options:

TableView not reloading

谁都会走 提交于 2020-03-26 02:37:26
问题 I am designing a one-to-one chatting interface using table view. This table view is modified to show bubbles as some new message arrives. The new message arrives through a push-notification in this case. I call following code in my function which receives message through the push notification: -(void)messageReceived: (NSString *)message{ _message=[message retain]; [tableView reloadData]; } However, it seems this does not reload my table view. If I place the call for reloadData in the

How to implement TextField search bar to filter tableview values Swift

。_饼干妹妹 提交于 2020-03-25 22:04:37
问题 I have created a custom textField bar on top of the ViewController to filter data values in UITableView . As I have a nested type of JSON so couldn't properly get how to use filter for it. I want to implement textField as a search bar with TableView. screenshot attached. Value which I need to filter is pickList -> textField textSearchChange function added for text search. Data is section wise and then values and is already displaying in tableView. Model: struct SectionList : Codable { let

How to implement TextField search bar to filter tableview values Swift

元气小坏坏 提交于 2020-03-25 22:03:34
问题 I have created a custom textField bar on top of the ViewController to filter data values in UITableView . As I have a nested type of JSON so couldn't properly get how to use filter for it. I want to implement textField as a search bar with TableView. screenshot attached. Value which I need to filter is pickList -> textField textSearchChange function added for text search. Data is section wise and then values and is already displaying in tableView. Model: struct SectionList : Codable { let

Swift change cell background colors in SOME tableView cells

廉价感情. 提交于 2020-03-23 07:51:09
问题 Two arrays. 1st has all the events, 2nd has the conflicting events(all exist in the 1st array). TableView shows all the events. I want to highlight the elements of the 2nd array in the table view cells 1st Array 21 items ["Bicycling with Friends - Start: Nov 1, 18 6:00 AM - End: Nov 1, 18 9:30 AM", "Yoga - Start: Nov 1, 18 6:00 PM - End: Nov 1, 18 7:33 PM", "Local Pub with Friends - Start: Nov 1, 18 7:33 PM - End: Nov 1, 18 11:00 PM", "Football Game - Start: Nov 3, 18 6:14 PM - End: Nov 3, 18

Swift UI Overlay a list to a background color

夙愿已清 提交于 2020-03-23 07:50:40
问题 I just want to set a Color as background color to my list. Can't find anything that work, It looks like is not possible, I don't want to change every single color of my row. Any tips how to do it? Looks like SwiftUI and List don't allow the background color, it allow only color per single raw. struct ContentView: View { var body: some View { ZStack { RadialGradient(gradient: Gradient(colors: [.orange, .red]), center: .center, startRadius: 100, endRadius: 470).edgesIgnoringSafeArea(.all)

UITableViewCell重用机制

不羁的心 提交于 2020-03-23 07:15:07
//重用 6.0以后dequeueReusableCellWithIdentifier: forIndexPath:indexPath 取代了 dequeueReusableCellWithIdentifier 并少写了!cell代码块 但是要和register并用 [tb registerClass:[TableViewCellclass] forCellReuseIdentifier:identifier]; TableViewCell*cell = [tableView dequeueReusableCellWithIdentifier:identifierforIndexPath:indexPath]; //不重用 浪费资源次之 NSString*iden = [NSStringstringWithFormat:@"ide%ld",(long)indexPath.row]; TableViewCell*cell = [tableView dequeueReusableCellWithIdentifier:iden]; if(!cell) { cell = [[TableViewCellalloc] initWithStyle:UITableViewCellStyleSubtitlereuseIdentifier:iden]; } .m文件需初始化initWithStyle: