简体   繁体   English

如何使用UIImages创建UITableView? -可可/客观C

[英]How do I create a UITableView with UIImages? - Cocoa/Objective-C

I'm trying to create an application for the iPhone with a table of categories. 我正在尝试为iPhone创建带有类别表的应用程序。 If I select a category it will display a UIImage. 如果我选择一个类别,它将显示一个UIImage。 However, I've been looking into it and I'm not sure exactly what to do. 但是,我一直在研究它,我不确定该怎么做。 Can anyone lend a hand? 谁能伸出援手?

It sounds like the easiest solution would be to use a UITableView in a Navigation Based Application. 听起来最简单的解决方案是在基于导航的应用程序中使用UITableView。 (Apple has samples on how to use this) (Apple有如何使用此示例)

Load the table with your categories. 用您的类别加载表。

When the user selects a category, push a new View from a Nib file onto the navigation stack. 当用户选择一个类别时,将一个新的视图从Nib文件推入导航堆栈。

This will allow you to use the same Nib for all categories and you just pass the image to load to the class, which handles loading it into a UIImageView. 这将允许您对所有类别使用相同的Nib,只需将图像传递给类即可,该类负责将其加载到UIImageView中。

For example: 例如:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:NO];

imageCatView *catView = [[imageCatView alloc] initWithNibName: @"imageCatView" bundle: nil];
catView.categoryID = [[[categories objectAtIndex: _selectedRow] objectForKey:@"CatID"] intValue];

[[self navigationController] pushViewController:catView animated:YES];
[catView release];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM