2012-08-02 2 views
1

안녕하세요 동적 테이블보기에 50 위치를 게시하는 응용 프로그램에서 작업 중입니다. 위치를 클릭하면 새로운 tableView 컨트롤러로 연결되어 그 위치에서 50 장의 사진이 게시됩니다 . tableViewController를 만든 다음 tableView에 IE Cellforrowatindexpath가 필요한 모든 파일을 포함하는 새 파일을 만들었습니다. 나는 주 tableViewController에서 연결하는 segue를 가지고 있지만 모든 정보는 tableViewController가 사용하는 메소드를 포함하는 newfile에 저장됩니다. tableViewController에 PrepareForSegue를 작성합니까? 아니면 테이블을 만드는 메소드가있는 파일에이 파일을 작성합니까? 또한 내가 tableViewCOntroller에 그것을 쓰면 동적으로 생성 된 셀 중 하나의 셀 이름에 어떻게 액세스합니까? 감사.테이블에서 segue를 준비하는 곳보기

-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{ 
    if([segue.identifier isEqualToString:@"Photos for location"]){ 
//I dont know what to use for the name 
     [segue.destinationViewController setPhotoInPlace: WHAT DO I CALL THIS!? 
    } 
} 

호출 이름은 이름과 위치 등의 정보가 사전의 배열을 생성하는 공개 API를 사용하는 다른 파일에서 왔습니다. 파일은 flickrFetcher입니다. 다음은 동적으로 셀을 만드는 코드입니다. self.brain은 flickerFetcher의 인스턴스이고 topPlaces는 NSdictionaries의 NSArray를 가져 오기 위해 flickrFetcher에서 호출되는 메서드입니다.

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath 
{ 
// Create an instance of the cell 
UITableViewCell *cell; 
cell = [self.tableView dequeueReusableCellWithIdentifier:@"Photo Description"]; 

if(!cell) 
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"Photo Description"]; 
// set properties on the cell to prepare if for displaying 
//top places returns an array of NSDictionairy objects, must get object at index and then object for key 

// the cellTitle has country then province, country goes in main title and province will go as subtitle. 
NSString * cellTitle = [[[[self.brain class] topPlaces] objectAtIndex:self.location] objectForKey:@"_content"]; 

NSRange cellRange = [cellTitle rangeOfString:@","]; 

NSString * cellMainTitle = [cellTitle substringToIndex:cellRange.location]; 

cell.textLabel.text = cellMainTitle; 

NSString* cellSubtitle = [cellTitle substringFromIndex:cellRange.location +2]; 

cell.detailTextLabel.text = cellSubtitle; 
//location is an int property that allows a new selection when using objectAtIndex 
self.location++; 
return cell; 
} 

답변

1

prepareForSegue:UIViewController 방법이다, 그래서보기 컨트롤러에 있어야합니다. sender 매개 변수는 segue를 일으킨 셀이어야합니다. 테이블 뷰 메서드 indexPathForCell:을 사용하면 관련 인덱스 경로를 얻을 수 있으며 cellForRowAtIndexPath:을 구현할 때 셀에 넣은 동일한 데이터를 찾을 수있을만큼 충분해야합니다.

(난 당신이 어떤 클래스가 구현 "새 파일"또는 무슨 뜻인지 확실하지 않다, 그래서 아무것도 영향을 미치는 경우 내가 말할 수 없습니다.) 새로운 파일로

+0

난의 서브 클래스를 만든 의미 그것 –

+0

괜찮아요, 만약 하위 클래스가 그것도 UIViewController'라는 것을 의미합니다. 그래서 당신이 부모에 그 메소드를 넣을 지, 아니면 자식이 기능적인 차이를 만들어서는 안됩니다. 아이가 새 컨트롤러에 전달하려는 정보에 더 잘 액세스 할 수 있습니다. 아마도 추측 할 수 있습니다. –

+0

부모에게 prepareforsegue를 넣은 다음 NSIndexPath *를 작성하면 indexPath = [self.tableView indexPathForCell : sender]; tableview가 선언되지 않았다고 선언하는 오류가 발생합니다. 그러나 자녀가있을 때이 오류가 해결됩니다. 또한 인덱스 경로가 행과 섹션 만 반환하면 어떻게 호출 이름을 얻을 수 있습니까? –

관련 문제