2012-07-12 4 views
0

단일 뷰 기반을 사용하여 응용 프로그램을 만들었습니다. 이제 15 개의 메뉴와 각 메뉴에 대한 설명을 표시해야합니다. 나는 UITableView을 사용하여 생각했습니다. 내가 프로그래밍 여기에 설명을 추가하기 위해 각각의 설명을 각 ViewController 또는 바로 가기를 만들 필요가 긴 텍스트를 & 이미지 content.Do를 표시한다 셀은 테이블 뷰 내 코드이 셀 때 UIAlertView을 만드는 것입니다개별적으로 UITableView 및 세부 뷰를 만드는 방법

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

static NSString *CellIdentifier = @"Cell"; 

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

// Set up the cell... 
cell.textLabel.font = [UIFont fontWithName:@"Helvetica" size:15]; 
cell.textLabel.text = [NSString stringWithFormat:@"Cell Row #%d", [indexPath row]]; 

return cell; 
} 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
// open a alert with an OK and cancel button 
NSString *alertString = [NSString stringWithFormat:@"Clicked on row #%d", [indexPath row]]; 
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:alertString message:@"" delegate:self cancelButtonTitle:@"Done" otherButtonTitles:nil]; 
[alert show]; 
[alert release]; 
} 

만졌어.

어떻게하면 긴 텍스트 및 이미지 display.Any 아이디어 pls 할 수 있습니다.

+0

그것은 당신이 그 (15) 뷰 컨트롤러뿐만 아니라 관련된 복잡성에 표시 할 내용에 따라 달라집니다. – rishi

+0

자세히보기에서 클릭 한 색인을 얻을 수 있으며 자세히보기를 표시 할 수 있습니다! – NSException

답변

2

네비게이션 컨트롤러를 사용하고 tableView를 푸시 할 수 있다고 생각합니다. 테이블의 셀을 선택하면 detailView (모든 셀에 대한 하나의 상세 뷰)를 푸시해야합니다. 이 기능은 동일한 형식의 세부 정보 데이터를 detailView에 표시해야하는 경우에만 작동합니다. 그렇지 않으면 각 선택에 대해 다른 화면을 사용해야하는 경우 화면을 모두 디자인하여 무거워지게 만들 수 있습니다.

+0

당신의 답변을 주셔서 감사합니다 이것은 단일 셀 설명입니다.하지만 15 테이블 뷰에 15 셀에 대한 설명이 필요합니다. 어떻게 달성 할 수 있습니까? – Dany

+0

모든 셀 설명의 UI 디자인이 같고 설명 필드의 필드 내용 만 변경해야하는 경우 선택한 row.index에 따라 내용을 변경할 수 있습니다. 모든 설명에 다른 UI가있는 경우 모두를 위해 다르게 디자인해야합니다. – Zaraki

2

UITextView 및 UIImageView를 만들어야하는보기 컨트롤러 내부에서 이미지와 텍스트로 초기화하는 단일 ViewController를 만들 수 있습니다. ViewController는 다음과 같아야합니다.

@interface ViewController : UIViewController { 
    UIImageView *imageView; 
    UITextView *textView; 
} 

-(id)initWithText:(NSString *)text image:(UIImage *)image; 

@end 

@implementation ViewController 

-(id)initWithText:(NSString *)text image:(UIImage *)image { 
    if (self = [super init]) { 
     //ImageView initialization 
     imageView.image = image; 
     //TextViewInitialization 
     textView.text = text; 
    } 
    return self; 
} 

@end 

뷰 컨트롤러에서는 테이블보기에서 셀에 해당 이미지와 텍스트가있는 2 개의 어레이를 만들 수 있습니다. 그런 다음 didSelectRowAtIndexPath는 : 필수는 다음과 같습니다

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    ViewController *vc = [[ViewController alloc]initWithText:[textArray objectAtIndex:indexPath.row] image:[imagesArray objectAtIndex:indexPath.row]]; 
    [[self navigationController] pushViewController:vc animated:YES]; 
    [vc release]; 
} 
+0

당신의 답변 주셔서 감사합니다 이것은 단일 셀 설명입니다.하지만 15 테이블 뷰에 15 셀에 대한 설명이 필요합니다. 어떻게 달성 할 수 있습니까? – Dany

+0

textArray에 15 개의 다른 문자열을 채워야합니다. 배열의 문자열 색인은 셀에 대응해야합니다 ... – Moonkid

관련 문제