【发布时间】:2012-04-11 18:28:27
【问题描述】:
我创建了一个 TableView(分组表视图)。我可以在表格视图中列出项目。但是我想知道下表是如何显示的
就像日历在左侧,而公历在右侧??格里高利如何显示在右侧?它是自定义 TableView,谁能帮我实现它?
【问题讨论】:
标签: iphone xcode uitableview cocoa-touch uikit
我创建了一个 TableView(分组表视图)。我可以在表格视图中列出项目。但是我想知道下表是如何显示的
就像日历在左侧,而公历在右侧??格里高利如何显示在右侧?它是自定义 TableView,谁能帮我实现它?
【问题讨论】:
标签: iphone xcode uitableview cocoa-touch uikit
这些只是带有style = UITableViewCellStyleValue1 和accessoryType = UITableViewCellAccessoryDisclosureIndicator 的常规单元格。
以编程方式制作:
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"YourIdentifier"];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
(请注意,在现实生活中您可能会尝试dequeueReusableCellWithIdentifier:,并且只有在返回 nil 时才创建一个新单元格。)
或者,如果您正在使用 IB,请将“样式”设置为“正确的细节”,将“附件”设置为“披露指示符”。
【讨论】:
cell.detailTextLabel.text = @"like, whatever"
您需要使用以下代码帮助您
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
UIImageView *v = [[[UIImageView alloc] init]autorelease];
v.backgroundColor = [UIColor clearColor]; // put clear color
[v setClipsToBounds:YES];
cell.selectedBackgroundView = v;
[cell setClipsToBounds:YES];
}
UIImageView *imgVBG=(UIImageView*)[cell selectedBackgroundView];
if(indexPath.row==0){
imgVBG.image=[UIImage imageNamed:@"TopImg.png"];
} else if((indexPath.section==0 && indexPath.row==4)||(indexPath.section==1 && indexPath.row==7)){
imgVBG.image=[UIImage imageNamed:@"BottomImg.png"];
} else {
imgVBG.image=[UIImage imageNamed:@"MiddleImg.png"];
}
}
【讨论】: