我正在解析 JSON 来为我的 TableView 获取数据。如果静态指定,我成功显示数据。在我的主视图中,它显示类别列表。当我选择一个单元格时,我需要通过传递来显示子类别来自主视图的categoryid。
NSDictionary *dict = [mmenuitems objectAtIndex:indexPath.row];
NSString *selectID = [NSString stringWithFormat:@"You selected %@",[dict objectForKey:@"id"]];
使用此代码,我在selectID中正确获取了categoryID。
我需要将此ID传递给subCatView,其中的数据是从
URL:http://mysite.in/getJson.php?method=showMenu&res_id=1&cat=收集的
我需要将 mainView 中的 catID 放入上面 URL 中的 cat 中。
如何更改 mainView 中的 didSelectRowAtIndexPath 和 subCatView 中的 viewDidLoad ?
最佳答案
您需要做的是:- 1.)首先在subCatView Controller 中创建一个NSString对象。 2.)之后,当您传递给 subCatView 时,在 NSString 对象中设置您的类别值。 3.) 在 subCatView Controller viewDidLoad 或您想要的其他方法中访问该值。
一些代码可以让您了解您必须做什么:- 在 subCategoryViewController .h 文件中执行以下操作:-
NSString *categorystring;
制造属性(property)并合成它。
在主视图 Controller 中执行:-
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
subCategoryViewController *subCatView=[[[subCategoryViewController alloc]initWithNibName:@"subCategoryViewController" bundle:nil]autorelease];
NSDictionary *dict = [mmenuitems objectAtIndex:indexPath.row];
NSString *selectID = [NSString stringWithFormat:@"You selected %@",[dict objectForKey:@"id"]];
[subCatView setCategorystring:cell.textLabel.text];
[[self navigationController]pushViewController:subCatView animated:YES];
}
现在在 subCategoryViewController 文件中访问此字符串。
关于iphone:根据主视图中选择的单元格在详细 View 中显示数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9257004/