2014-06-10 2 views
2

클라우드 코드 함수에서 반환되는 JSON 정보를 표시하는 UITableView가 있습니다. 어떤 이유로 반환 된 항목의 제목을 올바르게 표시하지만 각 셀의 부제목으로 가격을 표시 할 수는 없습니다. UITableViewCellStyleSubtitle으로 스타일을 설정하면 작동하지 않는 것 같아서 Implicit conversion from enumeration type 'enum UITableviewCellStyle' to different enumeration type이라는 경고 메시지가 나타납니다.UITableViewCell 자막이 보이지 않습니다.

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 

답변

6

등록한 셀은 기본이있는 UITableViewCell 스타일, 그것은 자막이 없습니다. 셀이 만들어지면 스타일을 변경할 수 없습니다.

UITableViewCellStyleSubtitle를 사용하는 간단한있는 UITableViewCell 하위 클래스 (또는 당신의 선택의 다른 스타일을) 만들

@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: 호출을 제거해야합니다.

옵션 1을 사용합니다. 내장 된 셀이 매우 제한되어 있으며 자신의보기 (예 : 라벨, 이미지보기)를 추가하려고합니다. 서브 클래스를 사용하면 속성을 사용하여보기에 액세스 할 수 있으며 액세스 할 때 태그와 같은 해킹을 사용할 필요가 없습니다.

+0

두 번째 옵션은 훨씬 더 유연하고 확장 가능합니다. – CrimsonChris

+0

좋은 오래된'viewWithTag :'게임을 좋아하는 경우에만. ;-) –

+0

'viewWithTag :'를 사용하지 않았습니다. 내가 왜? – CrimsonChris

0

표보기에서 자막이없는 경우 세부 텍스트 레이블 사용 cell.detailTextLabel.text = [배열 객체 키 : @ "값"];

관련 문제