【发布时间】:2012-03-14 07:47:17
【问题描述】:
当用户在tableview上选择一个单元格时,我想推送一个新视图,这怎么可能?
我想在新视图上打印选定的单元格数据?给我编码
【问题讨论】:
标签: iphone objective-c ios uitableview uiview
当用户在tableview上选择一个单元格时,我想推送一个新视图,这怎么可能?
我想在新视图上打印选定的单元格数据?给我编码
【问题讨论】:
标签: iphone objective-c ios uitableview uiview
重写 UItableViewDelegate 的这个委托方法。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//Value Selected by user
NSString *selectedValue = [displayValues objectAtIndex:indexPath.row];
//Initialize new viewController
NewViewController *viewController = [[NewViewController alloc] initWithNibName:@"NewViewController" bundle:nil];
//Pass selected value to a property declared in NewViewController
viewController.valueToPrint = selectedValue;
//Push new view to navigationController stack
[self.navigationController pushViewController:viewController animated:YES];
}
查看此链接了解更多信息
1) Table view tutorial
2)StackOverflow similar question
【讨论】:
您可以使用UINavigationController 并在didSelectRowAtIndePath: 方法中调用pushViewController:。
为了显示信息,我将创建一个新的UIViewController,并创建一些您可以设置用于显示信息的属性。
【讨论】:
您必须在方法“(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath”中实现代码。当您选择表格中的单元格时,将调用此方法。这就是为什么你必须实现你想要的。
希望下面的代码对你有所帮助。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (!yourObject) {
yourObject = [[yourViewController alloc] initWithNibName:@"yourViewController" bundle:nil];
}
UIBarButtonItem *backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:nil action:nil];
self.navigationItem.backBarButtonItem = backBarButtonItem;
[backBarButtonItem release];
[self.navigationController pushViewController:yourObject animated:YES];
}
【讨论】:
在didSelectRowAtIndexPath 方法中尝试这个,你可以创建类的对象,你可以
用户:NavigationController 或presentModleViewController 去另一个视图。
[self.navigationController pushViewController:yourClassobject animated:YES];
或
[self presentModalViewController:yourClassobject animated:YES];
【讨论】: