ios 中怎么让ios tableview 删除固定在某一行

scrollView 中的重要属性
self.scrollView.contentSize=CGSizeMake(); // scrollView中的内容大小
self.scrollView.contentOffset=CGPointMake(500, 500);// scrollView中,图片原点与,屏幕原点的x,y轴
self.scrollView.contentInset=UIEdgeInsetsMake(10, 20, 40, 80);// scrollView 控件与内容的内边距
self.scrollView.maximumZoomScale=210.f; //scrollView 中内容的最大放大尺寸
self.scrollView.minimumZoomScale=0.1f; // scrollView 中内容的最小缩小尺寸
self.scrollView.delegate= // 设置scrollView代理。 代理类必须实现UIScrollViewDelegate方法
scrollView 中的代理方法
// 开始拖拽时触发的代理事件
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
NSLog(@&将会开始拖拽&);
// 开始缩放时触发的代理事件
- (void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:(UIView *)view {
NSLog(@&将会开始缩放&);
// 正在缩放时触发的代理事件
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{
NSLog(@&正在缩放&);
return self.imageV
注:要实现缩放必须实现- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollV方法,返回需要缩放的控件。
tableView添加数据源和代理方法
self.tableView.dataSource= // 赋值类必须实现UITableViewDataSource协议
self.tableView.delegate= // 赋值类必须实现UITableViewDelegate协议
UITableView需要一个数据源(dataSource)来显示数据
UITableView会向数据源查询一共有多少行数据以及每一行显示什么数据等
凡是遵守UITableViewDataSource协议的OC对象,都可以是UITableView的数据源
tableView 数据源重要代理方法
// 可以不实现。默认为1,返回数为,tableView的组数
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
// 返回值为每组的行数,参数,section为组数
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return self.heros.
// 返回值为每行的TableViewCell indexPath中包含了。所在组与所在行
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
// 使用缓存池
UITableViewCell *tableViewCell=[tableView dequeueReusableCellWithIdentifier:@&A&];
if(tableViewCell==nil){
tableViewCell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@&A&];
LFHero *hero=self.heros[indexPath.row];
tableViewCell.textLabel.text=hero.
tableViewCell.detailTextLabel.text=hero.
tableViewCell.imageView.image=[UIImage imageNamed:hero.icon];
tableViewCell.accessoryType=UITableViewCellAccessoryDisclosureI
return tableViewC
注:当滚动列表时,部分UITableViewCell会移出窗口,UITableView会将窗口外的UITableViewCell放入一个对象池中,等待重用。当UITableView要求dataSource返回UITableViewCell时,dataSource会先查看这个对象池,如果池中有未使用的UITableViewCell,dataSource会用新的数据配置这个UITableViewCell,然后返回给UITableView,重新显示到窗口中,从而避免创建新对象
通过代码自定义cell
1.新建一个继承自UITableViewCell的类
2.重写initWithStyle:reuseIdentifier:方法
添加所有需要显示的子控件(不需要设置子控件的数据和frame, &子控件要添加到contentView中)
进行子控件一次性的属性设置(有些属性只需要设置一次, 比如字体\固定的图片)
3.提供2个模型
数据模型: 存放文字数据\图片数据
frame模型: 存放数据模型\所有子控件的frame\cell的高度
4.cell拥有一个frame模型(不要直接拥有数据模型)
5.重写frame模型属性的setter方法: 在这个方法中设置子控件的显示数据和frame
6.frame模型数据的初始化已经采取懒加载的方式(每一个cell对应的frame模型数据只加载一次)
注:initWithStyle:reuseIdentifier中创建UIButton一定要使用[UIButton buttonWithType:UIButtonTypeCustom];
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
if (self=[super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
UILabel *timeLable=[[UILabel alloc]init];
self.timeLable=timeL
self.timeLable.textAlignment=NSTextAlignmentC
self.timeLable.font=[UIFont systemFontOfSize:10];
self.timeLable.textColor=[UIColor grayColor];
[self addSubview:timeLable];
UIButton *textButton=[UIButton buttonWithType:UIButtonTypeCustom];
self.textButton=textB
[self addSubview:textButton];
UIImageView *iconImageView=[[UIImageView alloc]init];
self.iconImageView=iconImageV
[self addSubview:iconImageView];
tableView 常用方法
NSIndexPath *path = [NSIndexPath indexPathForRow:row inSection:0];
// 刷新指定行
[self.tableView reloadRowsAtIndexPaths:@[path] withRowAnimation:UITableViewRowAnimationRight];
// 刷新整个tableView
// 先更新表格,再滚动到指定行
[self.tableView reloadData];
NSIndexPath *indexPath=[NSIndexPath indexPathForRow:self.messageFrames.count-1 inSection:0];
[self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];
UIPickerView
使用dataSource来获得行数和列数
dataSource必须实现UIPickerViewDataSource协议
#pragma mark - UIPickerViewDataSource
// 返回pickerView一共有多少列
- (NSInteger) numberOfComponentsInPickerView:(UIPickerView *)pickerV
// 返回pickerView的第component列有多少行
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)
添加每一行每一列的内容必须使用delegate.&
delegate 需要实现UIPickerViewDelegate协议
#pragma mark - UIPickerViewDelegate
// 返回第component列的第row行显示什么内容 单纯文字
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)
// 返回第component列的第row行需要显示的视图
// 当一个view进入视野范围内的时候调用
// 当系统调用该方法的时候会自动传入可重用的view
可以使用自定义视图
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
// 当选中了pickerView的某一行的时候调用
// 会将选中的列号和行号作为参数传入
// 只有通过手指选中某一行的时候才会调用
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)
// 返回第component列每一行的高度
- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)
// 刷新第1列对应的数据
[pickerView reloadComponent:1];
// 让第1列滚动到第0行
[pickerView selectRow:0 inComponent:1 animated:YES];
// 让self.pickerView选中component 行,第row列
[self.pickerView selectRow:row inComponent:component animated:YES];
// 代码触发pickerView选中component 行,第row列 事件
[self pickerView:self.pickerView didSelectRow:row inComponent:component];
UIDatePicker&
创建时间选择器
// 1.创建时间选择器
UIDatePicker *datePicker = [[UIDatePicker alloc] init];
// 设置只显示日期
datePicker.datePickerMode = UIDatePickerModeD
// 设置日期为中文
datePicker.locale = [[NSLocale alloc] initWithLocaleIdentifier:@&zh_CN&];
datePicker.frame = CGRectMake(0, 44, 320, 162);
2.监听UIDatePicker的选择
* 因为UIDatePicker继承自UIControl,所以通过addTarget:...监听
UIToolbar&
.创建工具条 &注:toolbar init的时候一定要设置frame不然会没法点击
UIToolbar *toolbar = [[UIToolbar alloc] init];
toolbar.barTintColor = [UIColor purpleColor];
toolbar.frame = CGRectMake(0, 0, 320, 44);
[view addSubview:toolbar];
给工具条添加按钮
UIBarButtonItem *item0 = [[UIBarButtonItem alloc] initWithTitle:@&上一个& style:UIBarButtonItemStylePlain target:self action:@selector(previousBtnClick)];
UIBarButtonItem *item3 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
UIBarButtonItem *item1 = [[UIBarButtonItem alloc] initWithTitle:@&下一个& style:UIBarButtonItemStylePlain target:self action:@selector(previousBtnClick)];
UIBarButtonItem *item2 = [[UIBarButtonItem alloc] initWithTitle:@&完成& style:UIBarButtonItemStylePlain target:self action:@selector(previousBtnClick)];
toolbar.items = @[item0, item1, item3, item2];
先创建barItem,后添加监听事件
UIBarButtonItem *barItem=[[UIBarButtonItem alloc]initWithTitle:@&下一步& style:UIBarButtonItemStylePlain target:nil action:nil];
toolber.items =@[ barItem];
barItem.target=
barItem.action=@selector(test);
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:25871次
排名:千里之外
原创:64篇
(1)(6)(14)(2)(8)(16)(1)(11)(5)怎样让程序第一次加载的时候默认选中TableView的第一行 - iOS(iPhone/iPad/Mac)开发资料库
请问怎样让程序第一次加载的时候默认选中TableView的第一行,应该在代码的什么地方修改啊?
使tableview在界面启动后定位在x行
& & & & 在viewDidLoad中加入以下代码
& && & & &&&NSIndexPath *idxPath = [NSIndexPath indexPathForRow:x inSection:0];
& && & & &&&[self.tableView scrollToRowAtIndexPath:idxPath
& && && && && && && && &&&& & & & & & & && &&&atScrollPosition:UITableViewScrollPositionMiddle
& && && && && && && && && && && && && && && && && &&&animated:NO];
你先试试,有好多方法的!
iPhone开发资料库 (C)}

我要回帖

更多关于 ios tableview 滚动 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信