【发布时间】:2012-07-12 06:45:47
【问题描述】:
我已经使用基于单一视图的应用程序创建了一个应用程序。现在我必须显示 15 个菜单和每个菜单的描述。所以我想到使用 UITableView 插入其中。选择一个单元格时它应该显示长文本和图像内容。我是否必须为每个描述创建每个ViewController 或以编程方式添加描述的任何快捷方式
这是我的表格视图代码
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Set up the cell...
cell.textLabel.font = [UIFont fontWithName:@"Helvetica" size:15];
cell.textLabel.text = [NSString stringWithFormat:@"Cell Row #%d", [indexPath row]];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// open a alert with an OK and cancel button
NSString *alertString = [NSString stringWithFormat:@"Clicked on row #%d", [indexPath row]];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:alertString message:@"" delegate:self cancelButtonTitle:@"Done" otherButtonTitles:nil];
[alert show];
[alert release];
}
这是用于在单元格被触摸时创建UIAlertView。
我该如何做长文本和图像显示。请有任何想法。
【问题讨论】:
-
这将取决于您希望在这 15 个视图控制器上显示的内容以及所涉及的复杂性。
-
在详细视图中,您可以获得点击的索引,您可以显示其详细视图!!
标签: iphone ios xcode uitableview ios5