将 plist 从 UITableViewCell 推送到 UIView
我有一个通过键“Title”编译 UITableView 的 plist,该 plist 如下。表视图正确填充,我用以下内容推送视图控制器:
- (void) tableView: (UITableView*) tableView didSelectRowAtIndexPath: (NSIndexPath*) indexPath;
{
LocationsReviewViewController *nextViewController = [[LocationsReviewViewController alloc]init];
NSDictionary *rowData = [[[tableData objectAtIndex: indexPath.section] objectForKey: @"Rows"] objectAtIndex: indexPath.row];
nextViewController.title = [rowData objectForKey: @"Title"];
[self.navigationController pushViewController: nextViewController animated: YES];
}
How do I get nextViewController
上面保留一些有关选择表中哪个对象的信息?另外,如何在新的 nextViewController
视图上显示每个子树键中包含的字符串? ViewDidLoad 应该是什么样子?
这是 nextViewController 的 ViewDidLoad 当前的样子(描述是 UILabel)。为什么选择“LA Place 1”行时不显示@“3001 Sunset”:
- (void)viewDidLoad
{
[super viewDidLoad];
NSDictionary *dictionary = [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Data3" ofType:@"plist"]];
NSDictionary *subtree = [dictionary objectForKey: @"Subtree"];
description.text = [NSString stringWithFormat:@"%@",[subtree objectForKey:@"Item 2"]];
}
<array>
<dict>
<key>Rows</key>
<array>
<dict>
<key>Subtree</key>
<array>
<string>Los Angeles, CA</string>
<string>Tuesday</string>
<string>3001 Sunset</string>
</array>
<key>Title</key>
<string>LA Place 1</string>
</dict>
<dict>
<key>Subtree</key>
<array>
<string>New York, NY</string>
<string>Sunday</string>
<string>1400 Broadway</string>
</array>
<key>Title</key>
<string>NYC Place 1</string>
</dict>
<dict>
<key>Subtree</key>
<array>
<string>Austin, TX</string>
<string>Sunday</string>
<string>2400 Lamar Blvd</string>
</array>
<key>Title</key>
<string>Austin Place 1</string>
</dict>
</array>
<key>Title</key>
<string>Section1</string>
</dict>
</array>
</plist>
I have a plist that compiles a UITableView by the key "Title", the plist is below.The Table View populates correctly, I push a view controller with this:
- (void) tableView: (UITableView*) tableView didSelectRowAtIndexPath: (NSIndexPath*) indexPath;
{
LocationsReviewViewController *nextViewController = [[LocationsReviewViewController alloc]init];
NSDictionary *rowData = [[[tableData objectAtIndex: indexPath.section] objectForKey: @"Rows"] objectAtIndex: indexPath.row];
nextViewController.title = [rowData objectForKey: @"Title"];
[self.navigationController pushViewController: nextViewController animated: YES];
}
How do I get nextViewController
above to retain some information about which object in the table was selected? In addition, how do I show the strings contained in each subtree key on the new nextViewController
view? What should that ViewDidLoad look like?
Here's what it the ViewDidLoad currently looks like for the nextViewController (description is a UILabel). Why doesn't show @"3001 Sunset" when the "LA Place 1" row is selected:
- (void)viewDidLoad
{
[super viewDidLoad];
NSDictionary *dictionary = [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Data3" ofType:@"plist"]];
NSDictionary *subtree = [dictionary objectForKey: @"Subtree"];
description.text = [NSString stringWithFormat:@"%@",[subtree objectForKey:@"Item 2"]];
}
<array>
<dict>
<key>Rows</key>
<array>
<dict>
<key>Subtree</key>
<array>
<string>Los Angeles, CA</string>
<string>Tuesday</string>
<string>3001 Sunset</string>
</array>
<key>Title</key>
<string>LA Place 1</string>
</dict>
<dict>
<key>Subtree</key>
<array>
<string>New York, NY</string>
<string>Sunday</string>
<string>1400 Broadway</string>
</array>
<key>Title</key>
<string>NYC Place 1</string>
</dict>
<dict>
<key>Subtree</key>
<array>
<string>Austin, TX</string>
<string>Sunday</string>
<string>2400 Lamar Blvd</string>
</array>
<key>Title</key>
<string>Austin Place 1</string>
</dict>
</array>
<key>Title</key>
<string>Section1</string>
</dict>
</array>
</plist>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看您的 Data3.plist,我发现它是一个包含 2 个项目的字典。
因此,在您的
- (void)viewDidLoad
中,您的代码不正确。这应该是正确的代码:现在,如果您想将数据传递到下一个控制器,您应该添加
LocationsReviewViewController
对象的属性。在您的 LocationsReviewViewController.h 中:
在您的 LocationsReviewViewController.m 中:
当您分配 LocationsReviewViewController 对象时:
Looking at your Data3.plist I see it's a dictionary of 2 items.
So in your
- (void)viewDidLoad
your code is incorrect. This should be the correct code:Now, if you want to pass data to the next controller you should add a property to your
LocationsReviewViewController
object.In your LocationsReviewViewController.h:
In your LocationsReviewViewController.m:
When you alloc the LocationsReviewViewController object: