iOS 应用 View 选择

标签 ios objective-c xcode uitableview

我想开发一个 iOS 应用程序,它可以从我的 wordpress 博客中获取所有文章并正确地排列它们。每篇文章都有标题、图像和一些内容。对于第一个屏幕,我想做一些类似于自定义 UITableView 的东西,但我不确定这是否是实现它的正确方法。

http://a2.mzstatic.com/us/r30/Purple2/v4/5c/70/05/5c7005b2-ab76-33ab-e32f-5f7e861ef5e9/screen568x568.jpeg

这是我想在没有搜索栏的情况下做的事情。但是每篇文章的图像都会以这种方式布置,并且在图像下方有标题(不需要内容预览)。如果我使用 UITableView,我将在所有图像之间进行“分离”,这与此处的处理方式不完全相同。你知道我怎么能实现这样的目标吗?我是否必须以编程方式创建我的图形对象,或者使用 Storyboard/界面构建器工具是否可行?

最佳答案

您应该使用自定义的 UITableViewCell。以下是资源:

https://developer.apple.com/library/ios/documentation/userexperience/Conceptual/TableView_iPhone/TableViewCells/TableViewCells.html

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/

相关文章:

ios - xcode iOS Objective-C 中的多点触控

ios - Obj-c 为静态库导出 .h 文件 - 不想公开类定义

swift - 不使用 becomeFirstResponder() 将焦点设置到 UITextField

ios - Xcode 9.1 不支持 iOS 11.2.1 Xcode 需要 9.2

ios - 程序中出现意外的 '@'

ios - UIActivityViewController 的自定义 header

ios - 将 MDM 中的应用程序分发到 iOS 8 时出错

iphone - iOS应用启动或切换回前台的速度非常慢

ios - objective-c -在tableview单元格上解析xml时显示事件指示器

xcode - 如何将 FreeTDS 与 Xcode 结合使用?