uitableview

默认UITableViewCell的样式

下拉刷新

1
2
3
4
5
6
7
8
9
10
11
12
13
UIRefreshControl *refresh = [[UIRefreshControl alloc]init];
refresh.attributedTitle = [[NSAttributedString alloc]initWithString:@"刷新"];
[refresh addTarget:self action:@selector(refreshAction) forControlEvents:UIControlEventValueChanged];
self.refreshControl = refresh;

-(void)refreshAction
{
if (self.refreshControl.isRefreshing){
self.refreshControl.attributedTitle = [[NSAttributedString alloc]initWithString:@"加载中..."];

[self.refreshControl endRefreshing];
}
}

不允许点击

1
tableView.allowsSelection=NO;

滚动至某一行

1
[tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];

Table view data source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return tableViewData.count;
}

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

static NSString *iden = @"xxxxx";
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:iden];
if (cell==nil) {
cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:iden];
}

// do something

return cell;
}