Xcode 4.2가 있고 드롭 다운 메뉴를 만들려고합니다. 드롭 다운 메뉴에서 단어 나 숫자로 드롭 다운하고 싶습니다. 그런 다음 목록에서 항목을 선택하면 다른 페이지의 표에 나타나기를 원합니다. 내 질문은 : 어떻게 쓸 것인가? 감사합니다.UIPickerview 드롭 다운 메뉴의 경우
답변
먼저 File> New> New File으로 이동하여 프롬프트에 따라 nib 파일로 UIViewController 하위 클래스를 만듭니다.
이제 펜촉 (MyViewController.xib)을 엽니 다.
당신은 (그것은 중요하지 않습니다) 뷰에 UIPickerView 및 jQuery과 드래그 그러나 당신이 좋아하는을 준비해야한다.
다음 당신의 UIViewController 하위의 헤더 파일 (MyViewController.h)을 엽니 다.
@interface MyViewController : UIViewController {
라인의 끝에서
<UITableViewDelegate, UITableViewDataSource, UIPickerViewDelegate, UIPickerViewDataSource>
를 추가하는 것은 그래서 당신은 또한 당신의 tableview 및 선택기 및 참조를 추가해야합니다이
@interface MyViewController : UIViewController <UITableViewDelegate, UITableViewDataSource, UIPickerViewDelegate, UIPickerViewDataSource>
다음과 같습니다 두 개의 값 배열. 그냥 @end
이상 그런 다음 줄
@property (strong, nonatomic) IBOutlet UITableView* tableView;
@property (strong, nonatomic) IBOutlet UIPickerView* pickerView;
@property (strong, nonatomic) NSMutableArray* tableData;
@property (strong, nonatomic) NSMutableArray* pickerData;
를 추가 그냥 당신의 펜촉 파일에 가서 이러한 변수에 jQuery과 및 UIPickerView를 연결합니다.
이제 소스 파일 (MyViewController.m)에 당신은 당신에게 참조를 합성 할 필요가있다. 따라서 위임 방법, 그들 중 상당수가있을 것를 추가하는 단지 지금
@implementation MyViewController
아래의 파일에 @synthesize tableView, pickerView, tableData, pickerData
을 추가 할 수 있지만 그들은 꽤 자기 설명이야.jQuery과 대
위임 방법
- (NSInteger)numberOfSectionsInTableView:(UITableView*)tableView;
- (NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section;
- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
- (void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
UIPickerView의 위임 방법
jQuery과 다음
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView;
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component;
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component;
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component;
그들은 소스 파일에 추가되고 표기되어있다 :
- (NSInteger)numberOfSectionsInTableView:(UITableView*)tableView {
// The number of sections in the UITableView
return 1;
}
- (NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section {
// The number of rows in the UITableView
return [tableData count];
}
- (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];
}
// Set the table cell text to the appropriate value in tableData
cell.textLabel.text = [tableData objectAtIndex:indexPath.row];
return cell;
}
- (void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Whatever happens when you select a table view row.
}
UIPickerView :
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView;
{
// The number of sections in the UIPickerView
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component;
{
// The number of rows in the UIPickerView
return [pickerData count];
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component;
{
// The data for each row in the UIPickerView
return [pickerData objectAtIndex:row];
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
// whatever you want to happen when a row is selected.
// here I am assuming you want to remove from the picker and add to the table on selection
[tableData addObject:[pickerData objectAtIndex:row]];
[pickerData removeObjectAtIndex:row];
[tableView reloadData];
[pickerView reloadAllComponents];
}
좋아, 당신이해야 할 마지막 일은 대의원을 설정하고 데이터를 초기화한다. MyViewController
의 - (void)viewDidLoad
방법에서 다음 줄
tableView.delegate = self;
tableView.dataSource = self;
pickerView.delegate = self;
pickerView.dataSource = self;
tableData = [[NSMutableArray alloc] init]; // table starts empty
pickerData = [[NSMutableArray alloc] initWithObjects:@"1", @"2", @"3", @"4", @"5", nil]; // picker starts with values 1, 2, 3, 4, 5
[tableView reloadData];
[pickerView reloadAllComponents];
당신이 클래스에 대한 사양에서 찾을 수 있지만,이 사람이 지금은 적합해야합니다 몇 가지 더 위임 방법이 있습니다
를 추가합니다.안녕하세요.이 친구를 위해 null0pointer에게 감사드립니다. 탭으로 된 응용 프로그램에서이 작업을 수행 할 것인지 말 것인지를 선택합니다. :/ –
및 모든 코드를 따르려고했는데 잃어 버렸습니다. Xcode에 익숙하지 않고 모든 것이 어디 있는지 알아낼 수 없으며 단지 나 혼란 스럽습니다. uipickerview 등의 이미지를 업로드하고 어떤 코드가 어디에 있는지 말해 줄 수 있습니다. –
그래서 나는 당신이 물건을 찾을 수 있도록 몇 가지 이미지로 게시물을 업데이 트했습니다. 나는 또한 코드에있는 몇 가지 버그를 수정했습니다. 희망이 도움이됩니다. – null0pointer
- 1. 드롭 다운 메뉴의 contactform
- 2. 드롭 다운 메뉴의 공간
- 3. 드롭 다운 메뉴의 유용성
- 4. 드롭 다운 메뉴의 앵커
- 5. 드롭 다운 메뉴의 CSS 정렬
- 6. 메인 메뉴의 드롭 다운 메뉴를 유지하려면 어떻게해야합니까?
- 7. CSS 드롭 다운 메뉴의 최대 높이 설정
- 8. CSS가있는 드롭 다운 메뉴의 크기를 고정하는 방법
- 9. 머리글 메뉴의 드롭 다운 목록으로 Prestashop 범주
- 10. 드롭 다운 메뉴의 동적 변수 onchange
- 11. sukerfish 드롭 다운 메뉴의 인터넷 익스플로러 문제
- 12. Cufon이 드롭 다운 메뉴의 간격을 좁 힙니다.
- 13. 드롭 다운 메뉴의 너비를 동적으로 변경하십시오.
- 14. HAML form_tag 드롭 다운 메뉴의 문제
- 15. 드롭 다운 메뉴의 컨텐츠 유형 아이콘이 누락되었습니다.
- 16. IE에서 드롭 다운 메뉴의 링크가 작동하지 않습니다.
- 17. 젠드 양식의 드롭 다운 메뉴의 너비 설정
- 18. 내 드롭 다운 메뉴의 디스플레이가 작동하지 않습니다.
- 19. 드롭 다운 메뉴의 IE7 불투명도 문제
- 20. 자동 완성 드롭 다운 메뉴의 테두리
- 21. 드롭 다운 메뉴의 왼쪽에 설명되지 않은 여백.
- 22. HTML - 선택 드롭 다운 메뉴의 번호
- 23. URL 변수를 사용하는 드롭 다운 메뉴의 동적 기본 선택
- 24. 사용자 선택 드롭 다운
- 25. 다중 카테고리 드롭 다운 메뉴의 가장 기본적인 jQuery 구현은 무엇입니까?
- 26. 드롭 다운 메뉴의 기본 마우스를 어떻게 가리 키지 않습니까?
- 27. 부트 스트랩 오류가 드롭 다운 메뉴의 캐롤을 보여줍니다.
- 28. Chrome 및 IE의 드롭 다운 메뉴의 서브 메뉴 너비 문제
- 29. 드롭 다운 메뉴의 코드 개선 (HTML/CSS/JavaScript)
- 30. Ruby on Rails : 드롭 다운 메뉴의 요소의 고유성
정말 감사하겠습니다. –