2013-03-01 31 views
1

更新問題與推動DetailViewController和UITableView的

DetailViewController *wordDetail = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil]; 
wordDetail.wordWordString = [[NSString alloc] initWithString:[[myArray objectAtIndex:indexPath.row] objectForKey:@"word"]]; 
wordDetail.wordDefinitionString = [[NSString alloc] initWithString:[[myArray objectAtIndex:indexPath.row] objectForKey:@"definition"]]; 
wordDetail.title = [[myArray objectAtIndex:indexPath.row] objectForKey:@"name"]; 

[self performSegueWithIdentifier:@"showDetail" sender:self]; 

這裏是我的新的賽格瑞準備(做你的意思是我不需要說了,如果我用上面的方法,或者在所有?我其實現在如果確定我所有的標識都排着隊......你覺得呢?

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
if ([[showDetail] isEqualToString:@"showDetail"]) { 
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow]; 
NSDate *object = _objects[indexPath.row]; 
[[segue destinationViewController] setDetailItem:object]; 

圖可能會有所幫助,看看我的DetailViewController.m太...

-(void)setDetailItem:(id)newDetailItem 
{ 
if (_detailItem != newDetailItem) { 
    _detailItem = newDetailItem; 

    // Update the view. 
    [self configureView]; 
} 

if (self.masterPopoverController != nil) { 
    [self.masterPopoverController dismissPopoverAnimated:YES]; 
}   
} 

-(void)configureView 
{ 
//Update the user interface for the detail item. 

if (self.detailItem) { 
    self.detailDescriptionLabel.text = [self.detailItem description]; 
} 
} 


- (void)viewDidLoad 
{ 
    wordWordLabel.text = wordWordString; 
    wordDefinitionLabel.text = wordDefinitionString; 

    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 
    [self configureView]; 
} 

回答

1

你的第一部分代碼很好。然而,它正在創建一個DetailViewController,然後推動它。這意味着從來沒有Segue,所以你的第二個代碼根本就不重要。你需要決定你想使用哪一個。

[self.navigationController pushViewController:wordDetail animated:YES]; 

該行將一個viewController放在堆棧上。 OR

[self performSegueWithIdentifier:@"showDetail sender:self]; 

將在故事板中使用名爲showDetail的segue。你不能擁有兩個,你需要選擇。

故事板標識符 Storyboard Identifier

+0

確定。會相應調整並報告回來。謝謝。 – 2013-03-01 18:37:53

+0

好的。對原始問題進行編輯。謝謝。我不知道標識符是什麼。 – 2013-03-01 18:48:34

+0

標識符是您在Storyboard中設置的內容。點擊您在Storyboard中創建的segue,然後在右側的檢查器中,您會看到一個可以填寫的標識符字段。 – 2013-03-01 19:10:09