2012-10-28 5 views
0

저는 iPhone 개발에 초보자입니다. 이미 UITableView을 만들었습니다. 나는 모든 것을 연결하고 delegatedatasource을 포함 시켰습니다. 그러나 UITableViewCellAccessoryDetailClosureButton을 사용하여 세부보기 액세서리를 추가하는 대신 UITableViewCell을 클릭하고 UITableViewCell에 대한 자세한 정보가있는 다른보기로 연결해야합니다. 내 뷰 컨트롤러는 다음과 같습니다TableView를 클릭하면 다른보기로 연결됩니다.

ViewController.h

#import <UIKit/UIKit.h> 

@interface ViewController : UIViewController<UITableViewDataSource,UITableViewDelegate>{ 
    NSArray *tableItems; 
    NSArray *images; 
} 

@property (nonatomic,retain) NSArray *tableItems; 
@property (nonatomic,retain) NSArray *images; 

@end 

ViewController.m

#import "ViewController.h" 
#import <QuartzCore/QuartzCore.h> 
@interface ViewController() 

@end 

@implementation ViewController 
@synthesize tableItems,images; 
- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    tableItems = [[NSArray alloc] initWithObjects:@"Item1",@"Item2",@"Item3",nil]; 
    images = [[NSArray alloc] initWithObjects:[UIImage imageNamed:@"clock.png"],[UIImage imageNamed:@"eye.png"],[UIImage imageNamed:@"target.png"],nil]; 
} 

- (void)didReceiveMemoryWarning 
{ 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ 
    return tableItems.count; 
} 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 

    //Step 1:Check whether if we can reuse a cell 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"]; 

    //If there are no new cells to reuse,create a new one 
    if(cell == nil) 
    { 
     cell = [[UITableViewCell alloc] initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:@"cell"]; 
     UIView *v = [[UIView alloc] init]; 
     v.backgroundColor = [UIColor redColor]; 
     cell.selectedBackgroundView = v; 
     //changing the radius of the corners 
     //cell.layer.cornerRadius = 10; 

    } 

    //Set the image in the row 
    cell.imageView.image = [images objectAtIndex:indexPath.row]; 

    //Step 3: Set the cell text content 
    cell.textLabel.text = [tableItems objectAtIndex:indexPath.row]; 

    //Step 4: Return the row 
    return cell; 

} 

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{ 
    cell.backgroundColor = [ UIColor greenColor]; 
} 
@end 

이에 대한 몇 가지 지침을 필요를 .. 감사합니다 .. 저를 용서해주십시오이 바보 경우 문제.

답변

2

당신은 당신의 UIViewController의 방법에 따라 구현해야합니다 : 그것은 도움이 :)

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    ExampleDataItem *dataItem = [_dataSource objectAtIndex:[indexPath row]]; 

    DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil]; 
    detailViewController.dataSource = dataItem; 

    [self.navigationController pushViewController:detailViewController animated:YES]; 
} 

이 희망

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 

[예]

+0

어디 _dataSource 및 DetailViewController이 오는가? – lakesh

+0

그건 단지 예일뿐입니다. 귀하의 경우, self.tableItems는 데이터 소스가 될 것이며 DetailViewController는 귀하의 세부 사항보기를 제시하는 데 사용할 UIViewController의 이름이 될 것입니다. –

+0

DetailViewController는 세부 정보보기를 표시하는 데 사용할 UIViewController의 이름입니다. 이것은 내가 다른 ViewController가 필요하다는 것을 의미한다. 나는 이것을 말할 권리가 있는가? 예를 들어, SecondViewController? – lakesh

0

UITableViewDelegate 방법을 구현 측 방법에 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 귀하의 자세한 내용을 UIView (가정 당신은 전체적으로 참조를 가지고 viewDidLoad : method에이 뷰를 self.view에 할당했습니다. indexPath을 기반으로 상세 뷰의 내용을 업데이트하십시오. 또한 세부 뷰에서 "완료"버튼을 사용할 수 있습니다 다시 너의 테이블보기로 가라.

응용 프로그램이 UINavigationViewController를 사용하는 경우는, 대신 UIView의 detailedViewController (유형 UIViewController의)을 가지고 사용하여 탐색 컨트롤러에 그것을 밀어 :

[self.navigationController pushViewController:detailedViewController animated:YES]; 
+0

내 응용 프로그램에서 UINavigationViewController를 사용하지 않습니다. 그럼 어떻게? – lakesh

관련 문제