我使用基于单一 View 创建了一个应用程序。现在我必须显示 15 个菜单和每个菜单的描述。所以我想到使用 UITableView
插入其中。同时选择一个单元格它应该显示长文本和图像内容。我是否必须为每个描述或任何快捷方式创建每个 ViewController
以编程方式添加描述
这是我的表格 View 代码
- (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
。
如何显示长文本和图像。有什么想法吗。
最佳答案
我认为您可以使用导航 Controller 并在其上推送 tableView。在选择表格单元格时,您应该推送一个 detailView(所有单元格的一个详细 View )。仅当您必须在 detailView 中显示相同格式的详细信息数据时,这才有效。否则,如果您必须为每个选择使用不同的屏幕,那么您可以设计所有这些屏幕,这也会使其变得很重。
关于iphone - 如何分别创建UITableView和detail view,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11446324/