列表视图

简单列表
UITableView的核心事件(1)
// 获取列表的行数
- (NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section {
return [self.listData count];
}
UITableView的核心事件(2)
// 返回没个列表项的Cell
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier";
UITableViewCell*cell = [tableViewdequeueReusableCellWithIdentifier: SimpleTableIdentifier];
// 没有可重用的UITableViewCell对象时需要新创建一个,并指定重用标识
if (cell == nil) {
cell = [[UITableViewCellalloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:SimpleTableIdentifier];
}
UIImage*image;
if([indexPath row] > 4)
{
image = [UIImageimageNamed:@"face1.png"];
}
else
{
image = [UIImageimageNamed:@"face2.png"];
}
cell.imageView.image = image;
}
UITableView的核心事件(3)
// 缩进
- (NSInteger)tableView:(UITableView *)tableView
indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath {
// 偶数行可以被选择,奇数行不可以被选择
if([indexPath row] < 10)
return [indexPath row];
else
return 20-[indexPath row];
}