테이블보기가 있으며 특정 행을 두드리면 상세보기가 표시됩니다. 그러나 세부보기에 어떤 행이 두드려 졌는지 어떻게 알 수 있습니까? 예를 들어, 이름을 표시하는 MainController가 있습니다. "Johnny"를 탭하면 다음 화면에는 "Johnny"라는 문자열이있는 레이블이 표시됩니다. 내가 어떻게 그럴 수 있니?테이블 뷰 컨트롤러는 어떻게 세부 뷰와 통신합니까?
[편집 - 추가 된 코드]
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
ArticleView *article = [self.storyboard instantiateViewControllerWithIdentifier:@"ArticleView"];
[article.myLabel setText:@"random"];
[self.navigationController pushViewController:article animated:YES];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
NSDictionary *info = [json objectAtIndex:indexPath.row];
cell.textLabel.text = [info objectForKey:@"username"];
cell.textLabel.backgroundColor = nil;
cell.textLabel.textColor = [UIColor whiteColor];
cell.detailTextLabel.backgroundColor = nil;
cell.detailTextLabel.textColor = [UIColor whiteColor];
cell.detailTextLabel.text = [info objectForKey:@"user_pic"];
// Configure the cell...
return cell;
}
ArticleView.h
@interface ArticleView : UIViewController
@property (weak, nonatomic) IBOutlet UILabel *myLabel;
@end
ArticleView.m
->의 합성 속성
당신은 할 수
iOS 용, 코코아 터치입니까? 또는 Mac, 코코아? – vikingosegundo
iOS 용입니다 ... –
다음 번 태그를 올바르게 입력하십시오. Xcode는 (고급) 텍스트 편집기이기 때문에이 질문에 중요하지 않습니다. – vikingosegundo