2012-05-24 4 views
0

좋아요, 여기 제가 지난 며칠간 머리를 숙였습니다. 내 테이블보기에 대한 사용자 지정 셀을 만들었습니다. 나는이 셀에 대해 별도의 클래스 (customCell.h)를 만들고이를 Xcode에서 함께 연결했다. 사용자 정의 셀에는 사용자 정의 셀의 .h 파일에서 선언했으며 스토리 보드를 통해 사용자 정의 셀에 링크 된 네 개의 UIlabels가 있습니다.트위터 검색을 사용자 정의 테이블 뷰 셀에 연결하기

내 테이블 뷰 컨트롤러

내가 트위터에서 검색을하려고, 다음의 세부 사항 테이블보기 및 사용자 정의 셀을 채우는 오전의 .H 파일에 customCell.h 헤더 파일을 가져온

다양한 트윗. 문제는 내 사용자 지정 셀의 4 UIlabel 아울렛에 트윗 결과를 연결하는 방법을 모른다는 것입니다.

내 테이블보기 구현 파일에서 사용자 지정 셀의 콘센트 중 일부를 선언 할 때 (사용자 지정 셀의 .h 파일을 가져 왔음에도 불구하고) xcode는 이름을 인식하지 못한다고 말합니다.

아래 코드를 최대한 자세히 복사했습니다. 어떤 도움이라도 대단히 감사 할 것입니다. 미리 감사드립니다.

- (void)fetchTweets 
{ 
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ 
     NSData* data = [NSData dataWithContentsOfURL: 
         [NSURL URLWithString: @"THIS IS WHERE MY TWITTER SEARCH STRING WILL GO.json"]]; 

     NSError* error; 

     tweets = [NSJSONSerialization JSONObjectWithData:data 
               options:kNilOptions 
                error:&error]; 

     dispatch_async(dispatch_get_main_queue(), ^{ 
      [self.tableView reloadData]; 
     }); 
    }); 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    return tweets.count; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"TweetCell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
    } 

    NSDictionary *tweet = [tweets objectAtIndex:indexPath.row]; 
    NSString *text = [tweet objectForKey:@"text"]; 
    NSString *name = [[tweet objectForKey:@"user"] objectForKey:@"name"]; 
    NSArray *arrayForCustomcell = [tweet componentsSeparatedByString:@":"]; 

    cell.textLabel.text = text; 
    cell.detailTextLabel.text = [NSString stringWithFormat:@"by %@", name]; 



    return cell; 
} 

답변

1

테이블 뷰 셀의 기본 클래스 인 UITableViewCell의 인스턴스를 만듭니다. 귀하의 경우 customCell 클래스 (UITableViewCell 클래스를 확장)의 인스턴스를 만들어야합니다. 나는 희망

static NSString *CellIdentifier = @"TweetCell"; 

customCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

if (cell == nil) 
{ 
    cell = [[customCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
} 

// Get the tweet 
NSDictionary *tweet = [tweets objectAtIndex:indexPath.row]; 

이 당신을 도와 : 당신은 방법 cellForRowAtIndexPath 당신이 할 필요가!

스테펜.

+0

환상적 - 감사합니다. Steffen – Alan

관련 문제