UITableView:如何只实现一行与其他行不同
UITableView: how implement only one row different from the others
在 Storyboard 中(在 Xcode 6 中)我想设计这样的视图
user profile view
这些行是动态的,因为内容是从网络服务中获取的。我如何实现这个视图?
我尝试使用图像视图(上图带有用户名和图片)和下面的 table 视图,但是当我滚动 table 时,显然只滚动 table .
link 中的图像是 uitable 视图,只有第一行与其他行不同?如何实现只有一行与另一行不同?
谢谢
该视图可以是随 table 滚动的 tableHeaderView
,也可以是单元格。您可以根据需要在 table 视图中创建任意数量的原型单元,并为它们提供不同的重用标识符。在 cellForRowATIndexPath 中,放入一个 if-else 子句,并根据 indexPath.row.
出列您想要的任何单元格
给两个自定义单元格赋予不同的标识符。一个仅用于第一行,另一个用于 n-1 个单元格。
并将 cellForRowATIndexPath 加载为
在那之前取一个临时数组
NSArray *arr=[[NSArra alloc]initWithObjects:@"FirstIdentifer",@"SecondIdientfier"];
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *CellIdentifier = [self.menuItems objectAtIndex:indexPath.row];
if ([CellIdentifier isEqualToString:@"FirstIdentifer"]) {
Mycell *cell = (Mycell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"TempCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
//do your stuff
return cell;
}
else
{
static NSString *simpleTableIdentifier = @"SecondIdientfier";
cell1 = (Mycell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"Mycell" owner:self options:nil];
cell1 = [nib objectAtIndex:0];
//do your stuff
return cell1;
}
}
在 Storyboard 中(在 Xcode 6 中)我想设计这样的视图 user profile view
这些行是动态的,因为内容是从网络服务中获取的。我如何实现这个视图?
我尝试使用图像视图(上图带有用户名和图片)和下面的 table 视图,但是当我滚动 table 时,显然只滚动 table .
link 中的图像是 uitable 视图,只有第一行与其他行不同?如何实现只有一行与另一行不同?
谢谢
该视图可以是随 table 滚动的 tableHeaderView
,也可以是单元格。您可以根据需要在 table 视图中创建任意数量的原型单元,并为它们提供不同的重用标识符。在 cellForRowATIndexPath 中,放入一个 if-else 子句,并根据 indexPath.row.
给两个自定义单元格赋予不同的标识符。一个仅用于第一行,另一个用于 n-1 个单元格。
并将 cellForRowATIndexPath 加载为
在那之前取一个临时数组
NSArray *arr=[[NSArra alloc]initWithObjects:@"FirstIdentifer",@"SecondIdientfier"];
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *CellIdentifier = [self.menuItems objectAtIndex:indexPath.row];
if ([CellIdentifier isEqualToString:@"FirstIdentifer"]) {
Mycell *cell = (Mycell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"TempCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
//do your stuff
return cell;
}
else
{
static NSString *simpleTableIdentifier = @"SecondIdientfier";
cell1 = (Mycell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"Mycell" owner:self options:nil];
cell1 = [nib objectAtIndex:0];
//do your stuff
return cell1;
}
}