在基于导航的应用程序中使用 UIVIewController 填充 UIView
我正在制作一个测试应用程序,用于在基于导航的应用程序中列出电影,使用的是我在 application:didFinishLaunchingWithOptions:
的 appDelegate 中读取的 plist 文件中的数据。当我尝试转到第二个detailViewController时,标题部分发生了变化(我得到了电影的标题,但不是 UIView.title 中的年份,而是得到了类似“78898320”和空的内容) UIImageView 和 UILabels。我缺少
?
什么 src="https://i.sstatic.net/GjhRR.png" alt="从我的应用程序detailViewController 填充">
这是我在rootViewController 中的方法:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"YOU SELECTED: %d",indexPath.row);
detailViewController *detailView = [[detailViewController alloc] initWithNibName:@"detailViewController" bundle:nil];
NSDictionary *dict = [NSDictionary dictionaryWithDictionary:
[movies objectAtIndex:indexPath.row]];
[detailView fill:dict];
[self.navigationController pushViewController:detailView animated:YES];
[detailView release];
}
这是我在detailViewController 中填充UIView 的方法:
-(void)fill: (NSDictionary*) fillData
{
//movie = [NSDictionary dictionaryWithDictionary:fillData];
NSLog(@"DETAILS: %@",[fillData objectForKey:@"description"]);
self.title = [NSString stringWithFormat:@"%@ (%d)",
[fillData objectForKey:@"title"],
[fillData objectForKey:@"year"]];
//[movie objectForKey:@"title"];
self.img = [[UIImageView alloc] initWithImage:
[UIImage imageNamed:[fillData objectForKey:@"image"]]];
self.description = [fillData objectForKey:@"description"];
self.cast = [fillData objectForKey:@"cast"];
}
当我尝试时使用 NSLog 打印字典中的描述,它打印得很好。
I'm making a test application for listing movies in a Navigation Based Application using data from a plist file that I read in my appDelegate in the application:didFinishLaunchingWithOptions:
. When I try to go to the second detailViewController I get the title partially changed (I get the title of the movie but instead of the year in the UIView.title
I get something like "78898320" & empty UIImageView & UILabels. What am I missing?
Here is my method in the rootViewController:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"YOU SELECTED: %d",indexPath.row);
detailViewController *detailView = [[detailViewController alloc] initWithNibName:@"detailViewController" bundle:nil];
NSDictionary *dict = [NSDictionary dictionaryWithDictionary:
[movies objectAtIndex:indexPath.row]];
[detailView fill:dict];
[self.navigationController pushViewController:detailView animated:YES];
[detailView release];
}
Here is my method for filling the UIView in the detailViewController:
-(void)fill: (NSDictionary*) fillData
{
//movie = [NSDictionary dictionaryWithDictionary:fillData];
NSLog(@"DETAILS: %@",[fillData objectForKey:@"description"]);
self.title = [NSString stringWithFormat:@"%@ (%d)",
[fillData objectForKey:@"title"],
[fillData objectForKey:@"year"]];
//[movie objectForKey:@"title"];
self.img = [[UIImageView alloc] initWithImage:
[UIImage imageNamed:[fillData objectForKey:@"image"]]];
self.description = [fillData objectForKey:@"description"];
self.cast = [fillData objectForKey:@"cast"];
}
When I try to print the description from the dictionary using NSLog it prints out fine.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您正在使用
%d
作为您使用的对象。您应该使用
%@
来代替,因为它很可能是一个NSNumber
对象。You are using
%d
for the object that you get usingYou should use
%@
instead as it is most likely anNSNumber
object.您将必须更改一些内容才能使其正常工作。我猜你所有的标签和图像视图实际上都在 NIB 文件中。
通过这样做:
您实际上是在断开 NIB 文件中的属性和对象之间的连接,将其替换为新的实例。除非您手动将新视图添加到视图中,否则不会显示任何内容。
尝试使用:
这同样适用于:
尝试改为:
You will have to change some things to do it working. I guess all your labels and image views are actually in a NIB file.
By doing :
you are actually breaking the connection between the property and the object in the NIB file, by replacing it with a fresh new instance. Unless you add manually the new one to the view, nothing can appear.
Try using :
The same applies to :
Try instead :
如果您没有在图像视图中获取图像,因为您没有设置其框架并且没有将其添加到视图中(至少在这里)......
If you are not getting Image in image view because ur not setting its frame and you are not adding it to view (atleast here)....