我试图用uitableviewcontroller
来模仿iTunes的专辑页面,但后来我想我可能会走错了方向。做类似iTunes专辑页面的页面的最佳方式是什么?
我的计划是在tableView: cellForRowAtIndexPath:
做点事情。当indexPath.row == 0
,我做了专辑的描述(即上半部分),否则我做歌曲的描述(即下半部分)。
这里是我的代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell){
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
if (indexPath.row == 0){
CGRect imageFrame = CGRectMake(5, 5, 69, 69);
UIImageView *coverFram = [[UIImageView alloc] initWithFrame:imageFrame];
NSString *imagePath = [[NSBundle mainBundle] pathForResource:@"cover" ofType:@"jpg"];
coverFram.image = [[UIImage alloc] initWithContentsOfFile:imagePath];
[cell.contentView addSubview:coverFram];
}else{
NSInteger adjustedIndexPathRow = indexPath.row - 1;
cell.textLabel.text = [self.cellRow objectAtIndex:adjustedIndexPathRow];
}
return cell;
}
有两个地方我没有简单的想法实现它:
首先,在iTunes的专辑页面,有一个分段控制(见图)。当我按其他片段时,说“审查”,上部分保持在那里,而整个下部分已经改变。其次,我不知道如何关闭图像中的间隙显示(红圈)。
所以,我想可能还有其他一些更智能(或更容易)的方法来做到这一点。比如说,是否可以将页面分成两部分:然后由视图做上部分;并通过表格视图做下部分? (只是我的猜测)
请指教。谢谢。
它看起来与图像最顶端的视图是一个表标题视图(其中有一个水平滚动滚动视图或可能在其中的集合视图)。分段控件似乎位于节标题中,因为它在您滚动时粘到屏幕的顶部。当您单击其中一个按钮时,您只需更改表格视图显示的内容。 – rdelmar