这是我的问题。我将数据传递给mySQL的“第二个视图控制器”,目前效果很好。但是,当我选择任何from(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];
}
还有其他人使用笔尖而不是故事板。
有人可以指出我出错的地方或我从根本上错过了什么吗?
(我还有另一个完全使用导航控制器的项目。虽然这是我尝试使用标签栏导航的第一个项目)。
答案 0 :(得分:0)
使用故事板处理此问题的最佳方法是从mainViewController创建一个segue到详细视图。这可以来自您的实际单元格或控制器。在准备segue方法时,将对象传递给详细视图。这使用了fetchedResultsController,但想法是一样的。获取选定的单元格并将对象传递到详细信息视图。
以下是在使用细胞本身的segue时如何传递它的示例。从IB中的tableViewCell创建一个segue用于“选择”。将该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;
}
}
答案 1 :(得分:0)
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];
}