簡體   English   中英

從tableview到detailviewcontroller故事板問題

[英]tableview to detailviewcontroller storyboard issue

這是我的問題。 我有數據通過mySQL傳遞到“第二個視圖控制器”,目前效果很好。 但是,當我在( UITableView )單元格中的任何一個上進行選擇時,當前無法打開新視圖來顯示數據。

我相信代碼問題與

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
detailedViewController *productinfo = [self.storyboard instantiateViewControllerWithIdentifier:@"productDetails"];

//Retrieve current user array
foodProducts *currentProduct = [bakeryProductArray objectAtIndex:indexPath.row];
productinfo.productName = currentProduct.productName;
productinfo.productImage = currentProduct.productImgUrl;
productinfo.productDescription = currentProduct.productDescription;

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

}

還有其他人使用筆尖而不是情節提要來解決這個問題。

有人可以指出我哪里出了問題或根本上錯過了什么嗎?

(我有另一個僅與導航控制器完全兼容的項目。盡管這是我嘗試與標簽欄導航一起使用的第一個項目)。

用情節提要處理此問題的最佳方法是從mainViewController創建到詳細視圖的序列。 這可以來自您的實際單元或控制器。 在“准備segue”方法中,將對象傳遞到詳細信息視圖。 這使用了fetchedResultsController,但是想法是一樣的。 獲取選定的單元格,然后將對象傳遞到詳細信息視圖。

這是一個示例,說明如何使用單元本身的segue通過它。 從IB中的tableViewCell創建一個序列以進行“選擇”。 將該segue拖動到您的detailViewController並將標識符設置為ShowDetailView,然后添加以下prepareForSegue方法。

確保您的detailViewController上具有屬性(foodProduct),該屬性將保存對所選對象的引用。 那就是您將從mainViewController傳遞的內容。

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
{
    if ([[segue identifier] isEqualToString:@"ShowDetailView"]) 
    {
        DetailViewController *detailViewController = [segue destinationViewController];
        foodProducts *currentProduct = [bakeryProductArray objectAtIndex:[self.tableView indexPathForSelectedRow]];
        detailViewController.foodProduct = currentProduct;
    }
}
try this .....

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    Decriptionview *detail = [self.storyboard instantiateViewControllerWithIdentifier:@"Decription"];//@"Decription" is Storybord Id of UiViewController of Decriptionview
    detail.wndecDecription=[SortedDecription1 objectAtIndex:indexPath.row];
    detail.wndectitle=[SorttedTitle1 objectAtIndex:indexPath.row];
    detail.wndeclink=[SortedLink1 objectAtIndex:indexPath.row];
    detail.wndecdate=[SorttedDate1 objectAtIndex:indexPath.row];
    detail.imgeurl=[sorttedMainImage1 objectAtIndex:indexPath.row];
    [self.navigationController pushViewController:detail animated:YES];

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM