Objective c TableView:didSelectRowAtIndexPath,如何捕获行名称
我用随机数据填充表格视图。所以我不知道我有多少行,以及如何将它重定向到我想要的屏幕。我填写:Objective c TableView:didSelectRowAtIndexPath,如何捕获行名称,objective-c,ios,uitableview,Objective C,Ios,Uitableview,我用随机数据填充表格视图。所以我不知道我有多少行,以及如何将它重定向到我想要的屏幕。我填写: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { MyClass *currentScreenElement = [self.tableRows objectAtIndex:indexPath.row]; UITableView
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
MyClass *currentScreenElement = [self.tableRows objectAtIndex:indexPath.row];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:currentScreenElement.objectName];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:currentScreenElement.objectName];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
cell.textLabel.text = currentScreenElement.objectName;
return cell;
}
这个很好用。我有一个填充行的表视图。现在,我想重定向到新屏幕,并使用以下方法进行操作:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NewScreenClass *myScreen = [[NewScreenClass alloc] init];
self.detailViewController = [[CreateView alloc] initWithScreenDef:[myScreen returnScreenFromName:@"second"]];
[self.navigationController pushViewController:self.detailViewController animated:YES];
}
当然,我知道我在这里实际做的是为每一行创建相同的屏幕。但我怎样才能重定向到我想要的屏幕?
MycurrentScreenElement
对象包含属性:objectName
(在tableView中显示名称)和objectTarget
(屏幕定义)。两个都是字符串
我的问题是,我应该以某种方式将my currentScreenElement保存到行修补程序中,还是应该从dislay name中捕获objectName?在didSelectRowAtIndexPath中,您可以使用
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
然后从单元格中获取文本
cell.textLabel.text
为什么不能再次使用self.tableRows数组
MyClass *currentScreenElement = [self.tableRows objectAtIndex:indexPath.row];
NSString *title = [currentScreenElement objectName];
这与您设置该行所做的相同,只是再次使用它