我想开发一个 iOS 应用程序,它可以从我的 wordpress 博客中获取所有文章并正确地排列它们。每篇文章都有标题、图像和一些内容。对于第一个屏幕,我想做一些类似于自定义 UITableView 的东西,但我不确定这是否是实现它的正确方法。
这是我想在没有搜索栏的情况下做的事情。但是每篇文章的图像都会以这种方式布置,并且在图像下方有标题(不需要内容预览)。如果我使用 UITableView,我将在所有图像之间进行“分离”,这与此处的处理方式不完全相同。你知道我怎么能实现这样的目标吗?我是否必须以编程方式创建我的图形对象,或者使用 Storyboard/界面构建器工具是否可行?
最佳答案
您应该使用自定义的 UITableViewCell。以下是资源:
http://www.idev101.com/code/User_Interface/UITableView/customizing.html
http://www.appcoda.com/customize-table-view-cells-for-uitableview/
您可以使用继承自 UITableViewCell 的 XIB 创建 CustomCell 类。我们将按以下方式在 tableview 类 .m 文件中添加类别。我认为这是用于创建自定义单元格的最简单方法。
@interface UITableViewCell(NIB) @property(nonatomic,readwrite,copy) NSString *reuseIdentifier; @end - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 30; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *identifier=@"cell"; CustomCell *cell=[tableView dequeueReusableCellWithIdentifier:identifier]; if(cell==nil) { NSLog(@"New Cell"); NSArray *nib=[[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil]; cell=[nib objectAtIndex:0]; cell.reuseIdentifier=identifier; }else{ NSLog(@"Reuse Cell"); } cell.lbltitle.text=[NSString stringWithFormat:@"Level %d",indexPath.row]; id num=[_arrslidervalues objectAtIndex:indexPath.row]; cell.slider.value=[num floatValue]; return cell; } @end
关于iOS 应用 View 选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24981023/