iphone:根据主视图中选择的单元格在详细 View 中显示数据

标签 iphone objective-c ios uitableview

我正在解析 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/

相关文章:

iphone - 在 iphone sdk 中保持横幅(本地通知警报)

ios - 为什么我的 UITableViewCell 不取消选择并更新它的文本?

ios - 代码设计错误 : Provisioning profile cannot be found after deleting expired profile

ios - Swift 3 JSON 从 JSONArray 获取字符串不起作用

iphone - iphone 上的 class_addMethod (objective-c)

iphone - 检测 UITableViewCell 中的 url

iphone - 使用 iPhone LCD 与 Arduino

objective-c - 在 Objective C 中使用 Swift 中的 Objective C 枚举

objective-c - "QDDisplayWaitCursor"的替代品是什么?

ios - XCode Instruments:泄漏NSMallocBlock没有扩展细节的堆栈跟踪