如果我理解您的要求,您有一个 TableView (TableView1),其中每个单元格加载一个新视图 (MyView1),其内容取决于单元格的 indexPath。当您收到 isSelected 方法时,您不能将 indexPath 传递给您正在创建的新视图的构造函数吗?例如
–(void) selectRowAtIndexPath:(NSIndexPath*) indexPath animated:(BOOL) animated (UITableViewScrollPosition)scrollPosition {
UIView* view = [[[MyView1 alloc] initWithIndexPath:indexPath] autorelease];
//push or load the view
}
然后你需要创建你自己的继承自 UIView 的 MyView1 类,并添加构造函数以接受额外的参数并存储它。
如果你没有创建 UIView 或者它已经存在,那么我不完全确定你在问什么,所以我只是猜测一下。如果你问如何在 UIView 之间共享信息,而你的问题是每个 UIView 都不知道另一个。
在全局范围内共享有关您的应用程序的信息的一种简单方法是创建一个遵循单例设计模式的静态类,每个 UIView 都可以访问和修改该类。
//header
@interface MySingleton {
NSIndexPath* myIndexPath;
}
@property (nonatomic, retain) myIndexPath;
+(id) globalSingleton;
@end
在源 (.m) 文件中
//source
static MySingleton* singleton = nil;
@implementation MySingleton
@synthesize myIndexPath;
+(id) globalSingleton {
if (singleton == nil) {
singleton = [MySingleton new];
}
return singleton;
}
@end
我可能误解了您的问题,并且此解决方案可能不是解决您的问题的最佳方法。请澄清您的界面设计,我们可以提供更多帮助。祝你好运。
--编辑:
根据您的说法,第一个解决方案应该适用。
当您在 TableView 中收到“isSelected”消息时,您应该正在创建 WebView 对象。只需覆盖 init 函数以接受您需要的任何参数,在本例中为所选表的 NSIndexPath。我确信 developer.apple.com 上有一些示例,可以搜索使用自定义 UITableView 和导航视图控制器的示例项目。