【问题标题】:Tableview push to different viewTableview推送到不同的视图
【发布时间】:2012-11-26 09:12:57
【问题描述】:

我有这段代码,当按下一个单元格时,它会推送到一个新视图。这个新视图会根据按下的单元格的名称更改其标题。但是,所有单元格的视图都是相同的,如果我在一个单元格下更改某些内容,它会更改每个其他单元格的视图。我该如何做到这一点,以便每个单元格的每个视图都不同,而不会创建大量视图;这是不切实际的。谢谢。

推送代码:

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[self.tableView deselectRowAtIndexPath:indexPath animated:YES];

ACollection *newView = [[ACollection alloc] init];
newView.template = [[Global collections] objectAtIndex:indexPath.row];

newView.theTitle = [self.tableView cellForRowAtIndexPath:indexPath].textLabel.text;
[self.navigationController pushViewController:newView animated:YES];
}

【问题讨论】:

  • 您可以在您的第二类(Acollection)中使用NSString *mystring;,并在didSelectRowAtIndexPath 中将其值分配为newView.mystring=[self.tableView cellForRowAtIndexPath:indexPath].textLabel.text;,在您的第二类视图Viewdidload 中使用self.title=mystring

标签: iphone ios xcode


【解决方案1】:

theTitle 似乎是您在单元格选择中设置的局部变量。 但是,导航控制器在导航项中设置视图控制器的标题。 因此,您可以设置 AVCollections 标题,如 tis:

newView.navigationItem.title = [self.tableView cellForRowAtIndexPath:indexPath].textLabel.text;

在单元格选择期间。

【讨论】:

    【解决方案2】:

    好吧,现在考虑我们在数组中有字符串。(数组项的数量等于单元格的数量。或者我们可以说您正在从数组中加载详细信息。)。

    首先,在didSelectRowAtIndexPath:

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {    
             // Here we got the name of the item we are currently going to load
             NSString *item_Name   =   [contentArray objectAtIndex: indexPath.row];
             ViewController *yourViewController   =  [[ViewController alloc] initWithNIBName: @"ViewController" bundle: nil];
             yourViewController.navigationItem.title  =  item_Name;
             [self.navigationController pushViewController: yourViewController animated: YES];
    } 
    

    或者像lukya说的你可以使用

    NSString *item_Name   =   [self.tableView cellForRowAtIndexPath:indexPath].textLabel.text;
    

    如果要将单元格本身的标题标签设置为详细视图的标题。

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-07-27
      • 1970-01-01
      • 2021-04-23
      • 1970-01-01
      • 1970-01-01
      • 2017-12-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多