2011-02-17 6 views
3

다른 UITableViewController에 대한 상세보기 인 UITableViewController가 있습니다.UIDatePicker 및 UITableView

이 표에는 "날짜"라는 레이블이 붙은 셀이 있습니다. Apple의 "DateCell"예제 (http://developer.apple.com/library/ios/#samplecode/DateCell/Introduction/Intro.html)를 사용하여 셀을 터치 할 때 UIDatePicker을 추가하려고했습니다.

예제와 완전히 똑같은 방법으로 연결했습니다. 오른쪽 셀을 누를 경우에만 실행

if(indexPath.section == 1 && indexPath.row == 0) 
{ 
    //Date picker stuff 
} 

이 그것을 보장하는 것입니다 : 내가 변경 한 유일한 것은 내가이의 didSelectRowAtIndexPath 코드를 분리한다는 것입니다.

내 인생에서 나는 그것을 작동시킬 수 없습니다. 클릭하면 파란색으로 바뀝니다. 그것을 반복적으로 클릭하면 아무 일도 일어나지 않습니다.

UITableView의 맨 아래로 스크롤하면 흰색 사각형이 나타납니다. 반복적으로 클릭하면 결국 전체 표보기가 표시됩니다.

나에게 많은 의미가 없습니다. 제발 .. 내가 어떻게 할 수 있니?

더 많은 코드를 원한다면 제공 할 수 있지만 사실상 DateCell 코드와 동일합니다. 나는 대부분 복사/붙였다.

+0

아무도. 그래서 // Date picker stuff를 실제 코드로 대체하십시오. –

답변

6

가 당신이 사용하는 거라면 당신이 IB에서 선택기 개체가 있는지 확인합니다 사전에

감사합니다,

Clif 후 함께 IBOutlet 참조를 만들고는 IB 객체에 연결합니다. 내 pickerView를 IB에 숨기고 필요시 표시되도록 설정했습니다. 그렇지 않으면 필요에 따라 간단하게 인스턴스화 할 수 있습니다.

귀하의 didSelectRowAtIndexPath에서 아래 코드를 시도해보고 결과를 볼 수 있습니다. 당신이 선택 도구 뷰 선택 변경과 같은 셀의 라벨을 업데이트 할 경우 pickerView:didSelectRow: 방법을 구현해야 그 후

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    if (**your cell/section selection logic here**) { 
     [self.view endEditing:YES]; // resign firstResponder if you have any text fields so the keyboard doesn't get in the way 
     [self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:YES]; // Scroll your row to the top so the user can actually see the row when interacting with the pickerView 

     // Pickerview setup 
     [self.typePicker setCenter:CGPointMake(150, 500)]; // place the pickerView outside the screen boundaries 
     [self.typePicker setHidden:NO]; // set it to visible and then animate it to slide up 
     [UIView beginAnimations:@"slideIn" context:nil]; 
     [self.typePicker setCenter:CGPointMake(150, 250)]; 
     [UIView commitAnimations];   
    } 
} 

...

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component 
{ 
    // Your code to get the current table view cell and update it with the data from your pickerView 
} 

것은 당신의 ViewController가 대리인으로 선언되어 있는지 확인합니다 tableView <UITableViewDelegate> 및 pickerView의 경우 '

이렇게하면 좋은 시작이 될 것입니다. 질문 등이 있으면 알려주세요

건배, 로저 당신의 질문에 대답, 심지어 나에게 dateCell 예를 다운로드합니다

+0

글쎄, 그래서 내가 늦은 밤에 StackOverflow에 게시해서는 안됩니다. 내가 문제가있는 이유는 UIDatePicker를 내 윈도우에 추가하지 않았고 콘센트를 연결하지 않았기 때문이라는 것을 알게되었습니다. 이것은 내 첫 아이폰 앱으로, 지금까지 대부분의 객체를 코드에서 인스턴스화했습니다. 나는 이것에 대해서도 똑같이해야한다. 귀하의 의견은 이러한 실현을 촉발 시켰으므로 귀하에게 크레딧을드립니다. 시간을 낭비해서 죄송합니다. – clifgriffin