2014-02-20 4 views
2

tableview 셀에 사용자 정의보기를로드하려고합니다. 정확히, 개체 배열을 가지고 있고 사용자 지정보기를 사용하여 셀에 내용을 동적으로로드하려고합니다. 내가보기에 ... N1, N2의 값을 DISPALY하기 위해 노력하고있어사용자 정의 및 동적보기 - 내용이있는 UITableView 셀

{ ID = 1; date = "2014-01-06"; n1 = 12; n2 = 3; n3 = 34; n4 = 5; n5 = 44; n6 = 24; report = "<null>"; win = 123443; } 

나는이 방법을 만들어 : 내 객체 구조는

@interface MenuCell : UITableViewCell 

@property (nonatomic, strong) BallView *ballView; 
@property (nonatomic, strong) IBOutlet UILabel *labelDescription; 
@property (nonatomic, strong) IBOutlet UILabel *labelDetails; 
@property (nonatomic, strong) IBOutlet UIView *ballsView; 

+ (CGFloat)getCellHeight; 

내 BallView.h

@interface BallView : UIView 

@property (nonatomic, strong) IBOutlet UIImageView *imgSelectedBall; 
@property (nonatomic, strong) IBOutlet UILabel *labelNo; 
@property (nonatomic, strong) IBOutlet UIActivityIndicatorView *spinner; 

+ (BallView*)showInView:(UIView*)parrentView xOrigin:(NSInteger)xOriginValue; 

@end 

내 BallView.m

+ (BallView*)showInView:(UIView*)parrentView xOrigin:(NSInteger)xOriginValue { 
    NSArray* nibViews = [[NSBundle mainBundle] loadNibNamed:@"BallView" owner:self options:nil]; 
    BallView *modal = [nibViews objectAtIndex:0]; 
    modal.frame = CGRectMake(xOriginValue,ball_yOrigin, ball_width, ball_height); 
    [modal setBackgroundColor:[UIColor greenColor]]; 
    [parrentView addSubview:modal]; 
    return modal; } 
,691,363 jQuery과 위임 메소드 내의 ViewController에서210

나는이 방법 (필자는 한 숫자 값으로 테스트를했다)의 정보를로드하려고 :

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
    { 
     static NSString *CellIdentifier = @"NewsCell"; 
     MenuCell *cell = (MenuCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

     if (cell == nil) { 
      NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"MenuCell_3" owner:self options:nil]; 
      for (id currentObject in topLevelObjects){ 
       if ([currentObject isKindOfClass:[UITableViewCell class]]){ 
        cell = (MenuCell *) currentObject; 
       } 
      } 
     } 

     __block TickteObj *obj = [self.dataSourceArray objectAtIndex:indexPath.row]; 

     if (obj){   
      __block CGFloat leftMark = ball_offSet; 
      for (int i = 1 ; i<5 ; i++){ //5 = my object has 6 numbers which must be displayed 
       __block BallView *ballView = [BallView showInView:cell.ballView xOrigin:leftMark]; 
       cell.ballView.labelNo.text = obj.n1; 

       leftMark+=ball_offSet+ballView.frame.size.width; 
      } 
     } 
     return cell; 
    } 

내가 내 셀의 값을로드하는 데 도움이 필요합니다. 감사 !

+0

어떤 값을로드 하시겠습니까? 당신이 가지고있는 것만으로는 효과가 없습니다. 아니면 다른 n 값 (TickteObj의 인터페이스 표시)에 문제가 있습니다. – Wain

+0

frst에 대해 obj.no1 (i = 0, obj.no2의 값을 i = 1)의 값을 표시하려고합니다. ifible을 사용하기 때문에 if 문을 사용하지 않습니다. 보기의 증가를위한 furture에서 ... –

답변

2

TickteObj에서 제공하는 인터페이스를 변경해야합니다.

- (NSString *)nValueAtIndex:(NSInteger)index 

을 아마 배열 내부적 N 값을 저장 : 오히려 다수의 특성 (n1, n2 ... nx)를 제공하는 대신, 그 인덱스 기반의 방법을 제공한다. 이런 식으로 얼마나 많은 값이 있고 루프가 쉽게 작동하는지 상관하지 않습니다.

관련 문제