UITableViewCell字幕未显示

ho

我的UITableView显示了从云代码函数返回的JSON信息。由于某种原因,它可以正确显示要退回的商品的标题,但是我无法将价格显示为每个单元格的字幕。将样式设置为UITableViewCellStyleSubtitle似乎不起作用,并给了我警告Implicit conversion from enumeration type 'enum UITableviewCellStyle' to different enumeration type

MatchCenterViewController.h:

#import <UIKit/UIKit.h>
#import <Parse/Parse.h>
#import "AsyncImageView.h"
#import "SearchViewController.h"

@interface MatchCenterViewController : UIViewController <UITableViewDataSource>

@property (nonatomic) IBOutlet NSString *itemSearch;

@property (nonatomic, strong) NSArray *imageURLs;
@property (strong, nonatomic) NSString *matchingCategoryCondition;
@property (strong, nonatomic) NSString *matchingCategoryLocation;
@property (strong, nonatomic) NSNumber *matchingCategoryMaxPrice;
@property (strong, nonatomic) NSNumber *matchingCategoryMinPrice;


@property (strong, nonatomic) NSArray *matchCenterArray;


@end

MatchCenterViewController.m:

#import "MatchCenterViewController.h"
#import <UIKit/UIKit.h>

@interface MatchCenterViewController () <UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, strong) UITableView *matchCenter;
@end

@implementation MatchCenterViewController



- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
//        self.matchCenter = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
//        _matchCenter.dataSource = self;
//        _matchCenter.delegate = self;
//        [self.view addSubview:self.matchCenter];
    }
    return self;



}




- (void)viewDidLoad
{

    [super viewDidLoad];



    self.matchCenter = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewCellStyleSubtitle];
    self.matchCenter.frame = CGRectMake(0,50,320,self.view.frame.size.height-200);
    _matchCenter.dataSource = self;
    _matchCenter.delegate = self;
    [self.view addSubview:self.matchCenter];

    self.matchCenterArray = [[NSArray alloc] init];



}

- (void)viewDidAppear:(BOOL)animated
{

    self.matchCenterArray = [[NSArray alloc] init];

    [PFCloud callFunctionInBackground:@"MatchCenterTest"
                       withParameters:@{
                                        @"test": @"Hi",
                                        }
                                block:^(NSDictionary *result, NSError *error) {

                                    if (!error) {
                                         self.matchCenterArray = [result objectForKey:@"Top 3"];


                                        dispatch_async(dispatch_get_main_queue(), ^{
                                            [_matchCenter reloadData];
                                        });


                                        NSLog(@"Test Result: '%@'", result);
                                    }
                                }];

    [self.matchCenter registerClass:[UITableViewCell class] forCellReuseIdentifier:@"Cell"];


}




- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
     return [self.matchCenterArray count];
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{


    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];


    NSDictionary *matchCenterDictionary= [self.matchCenterArray objectAtIndex:indexPath.row];

    cell.textLabel.text = [matchCenterDictionary objectForKey:@"Title"];// title of the item

    cell.detailTextLabel.text = [matchCenterDictionary objectForKey:@"Price"];// price of the item

    return cell;


}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}




/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
马蒂亚斯·鲍赫(Matthias Bauch)

您注册的单元格是默认样式的UITableViewCell,它没有子标题。创建单元格后,您将无法更改其样式。

您基本上有两个选择:

创建一个简单的UITableViewCell子类,该子类使用UITableViewCellStyleSubtitle(或您选择的任何其他样式)

@interface MyTableViewCell : UITableViewCell
@end

@implementation MyTableViewCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    // overwrite style
    self = [super initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuseIdentifier];
    return self;
}
@end

...

[self.matchCenter registerClass:[MyTableViewCell class] forCellReuseIdentifier:@"Cell"];

或者返回到旧式出队技术,如果无法出队,则在其中创建单元

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (!cell) {
        // if no cell could be dequeued create a new one
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
    }
    /* configure */
}

如果这样做,则必须删除registerClass:forCellReuseIdentifier:呼叫。

我会选择第一种方法,因为很可能很快您就会发现内置单元格非常有限,并且您想添加自己的视图(例如标签,图像视图)。而且,如果您使用子类,则可以使用属性来访问这些视图,而不必使用诸如标记之类的技巧来访问它们。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

UITableViewCell的辅助箭头未显示

来自分类Dev

UITableViewCell中的内容未显示

来自分类Dev

UITableViewCell中的内容未显示

来自分类Dev

UITableViewCell子视图未显示

来自分类Dev

设置initwithstyle时,UITableViewCell不显示字幕:UItableviewsubtitle

来自分类Dev

UITableViewCell的字幕不会更新

来自分类Dev

本地通知内容:字幕或正文未显示[Swift 5]

来自分类Dev

xcode 操场中的 UITableView 未显示文本/字幕

来自分类Dev

Swift UITableViewCell IBOutlets未显示在StoryBoard中

来自分类Dev

UITableViewCell selected背景阴影未显示在设备上

来自分类Dev

UITableViewCell不显示文本或NSMutable数组未正确设置

来自分类Dev

UITableViewCell selected背景阴影未显示在设备上

来自分类Dev

VideoJS不显示字幕

来自分类Dev

第一张幻灯片后的字幕未显示为flexslider

来自分类Dev

UITableViewCell字幕无法从数组正确更新

来自分类Dev

Bootstrap Carousel:字幕不显示

来自分类Dev

如何使MPC显示强制字幕?

来自分类Dev

字幕已停止显示的SMPlayer

来自分类Dev

UITableViewCell的图像未缩进

来自分类Dev

UITableViewCell附件未着色

来自分类Dev

UITableViewCell的图像未缩进

来自分类Dev

UITableViewCell标签未更新

来自分类Dev

UItableViewCell自定义单元格未显示详细信息

来自分类Dev

iOS UITableViewCell附件未正确显示,但披露指示器除外

来自分类Dev

初始化后未显示带有笔尖的UITableViewCell

来自分类Dev

在自定义UITableViewCell中未显示Objective-C图像

来自分类Dev

VLC录制按钮未保存DVD字幕

来自分类Dev

使用Powershell清理未使用的字幕文件

来自分类Dev

如何从uitableviewcell显示uidatepicker

Related 相关文章

热门标签

归档