내 첫 번째 앱을 만드는 중입니다. 내 애플 리케이션 사이드 팝업 메뉴가 나타납니다. 슬라이딩 메뉴 부분을 UITableView로 구현했습니다. 이제 텍스트 옆에 이미지가있는 사이드 메뉴를 채우고 싶습니다. 탭이 있으면 다른보기 컨트롤러를 밀고 싶습니다. 이 작업을 수행하는 가장 좋은 방법은 무엇입니까? 감사합니다사이드 메뉴 바에 항목을 추가하는 방법은 무엇입니까?
0
A
답변
0
user132490 말했듯이, 아마도 tableView에 행을 추가하고 싶습니다. 자습서는 http://www.appcoda.com/uitableview-tutorial-storyboard-xcode5/입니다. Xcode 5 용이지만 여전히 작동합니다. "테이블 데이터 추가"및 아래에서 유용 할 수 있습니다. 사실, 요약 이전에이 튜토리얼에서는 각 셀의 텍스트 옆에 미리보기 이미지를 추가하도록 안내합니다.
행운을 빈다.
0
테이블에 이미지와 텍스트를 넣으려면 UITableViewCell
하위 클래스를 만들고 이미지보기와 레이블을 선언해야합니다. IB에서 이미지보기 및 레이블을 작성하고 프로토 타입 셀을 작성한 다음 이미지보기 및 레이블을 추가하십시오.
일단 작업을 완료하면 테이블 내용을 배열해야합니다. 그것은 다음과 같이이다 :
NSDictionary *option1 = [NSDictionary dictionaryWithObjectsAndKeys:@"image1.png",@"image",@"Option1",@"desc", nil];
NSDictionary *option2 = [NSDictionary dictionaryWithObjectsAndKeys:@"image2.png",@"image",@"Option2",@"desc", nil];
NSDictionary *option3 = [NSDictionary dictionaryWithObjectsAndKeys:@"image3.png",@"image",@"Option3",@"desc", nil];
NSDictionary *option4 = [NSDictionary dictionaryWithObjectsAndKeys:@"image4.png",@"image",@"Option4",@"desc", nil];
NSDictionary *option5 = [NSDictionary dictionaryWithObjectsAndKeys:@"image5.png",@"image",@"Option5",@"desc", nil];
//assign NSDictionaries to array
self.menuArray = [NSMutableArray arrayWithObjects:option1,option2,option3,option4,option5, nil];
그리고이 같은 테이블 뷰 위임 방법이 있어야합니다 :
@property NSMutableArray *menuArray;
당신의 viewDidLoad
에서 :
@interface
에서 밀어에서
#pragma mark Table View delegate methods
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [menuArray count];
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
//return row height
return 32;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *cellIdentifier [email protected]"Cell";
//assign TableCell.h to access custom properties
TableCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
//get dictionary from menuArray
NSDictionary * dict = [self.menuArray objectAtIndex:indexPath.row];
UIImage *imageIcon = [UIImage imageNamed:[dict objectForKey:@"image"]];
//set image
[cell.img setImage:imageIcon];
//set the label text
cell.label.text = [dict objectForKey:@"desc"];
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//research more about pushing another view controller.
//if chosen was option1
if (indexPath.row == 0)
{
NSLog(@"option1");
}
//if chosen was option2
if (indexPath.row == 1)
{
NSLog(@"option2");
}
//if chosen was option3
if (indexPath.row == 2)
{
NSLog(@"option3");
}
// if chosen was option4
if(indexPath.row == 3)
{
NSLog(@"option4");
}
// if chosen is option5
if(indexPath.row == 4)
{
NSLog(@"option5");
}
}
을 다른보기 컨트롤러에게, 왜냐하면 그것은 더 작은 것을 연구하려고 노력한다. 더 많은 설명. https://github.com/ECSlidingViewController/ECSlidingViewController
그러나이 코드를 사용하면 테이블을 채울 수 있어야하며 셀을 선택하면 로그가 표시됩니다. 희망이 도움이 :) :
관련 문제
- 1. Rhythmbox 사이드 패널에 항목을 추가하는 방법은 무엇입니까?
- 2. 워드 프레스 사이드 바에 '추가'영역을 추가하는 가장 좋은 방법은 무엇입니까?
- 3. Magento 블로그의 사이드 바에 블록을 추가하는 방법은 무엇입니까?
- 4. MediaWiki 사이드 바에 언어 링크를 추가하는 방법은 무엇입니까?
- 5. 각 Wordpress 게시물의 사이드 바에 맞춤 콘텐츠를 추가하는 방법은 무엇입니까?
- 6. 사이드 바에 이온 인증 로그인 양식을 추가하는 방법은 무엇입니까?
- 7. 워드 프레스의 사이드 바에 서브 메뉴 추가
- 8. $ _GET에 사이드 바에 클래스를 추가하는 방법
- 9. 앱 페이지에서 사이드 바에 링크를 추가하는 방법
- 10. Android 앱에 메뉴 항목을 추가하는 방법은 무엇입니까?
- 11. 옵션 메뉴 항목을 추가하는 방법은 무엇입니까?
- 12. 모듈에 탭 메뉴 항목을 추가하는 방법은 무엇입니까?
- 13. 전자 메뉴가있는 Mac의 메뉴 바에 맞춤 메뉴를 추가하는 방법은 무엇입니까?
- 14. 메뉴 항목을 작성하는 방법 상단 바에 채우기
- 15. 액션 바에 메뉴 항목을 정렬하는 법?
- 16. Skadate 사이드 바에 HTML 추가
- 17. 사이드 바에 양식 표시
- 18. MailComposer가 사이드 바에 열림
- 19. 사이드 바에 아래쪽으로 채우기
- 20. chatroom 사이드 바에 온라인 사용자보기
- 21. 사이드 바에 누출 된 컨테이너
- 22. 노드 필드를 사이드 바에 삽입하십시오.
- 23. 사이드 바에 패딩 문제가 있습니다.
- 24. Android : ActionBarSherlock에 메뉴 항목을 추가하는 방법 MapActivity
- 25. iPad 용 사이드 바에 Keynote의 모방을 만드는 방법은 무엇입니까?
- 26. 모든 문서를 Sphinx GlobalToc 사이드 바에 포함시키는 방법은 무엇입니까?
- 27. 특정 위젯이 사이드 바에 표시되는지 여부를 확인하는 방법은 무엇입니까?
- 28. magento의 오른쪽 사이드 바에 추천 제품을 추가하는 방법
- 29. 코드를 통해 정적 사이드 바에 Wordpress 위젯 위젯을 추가하는 방법?
- 30. 메뉴 항목을 업데이트하는 방법은 무엇입니까?
가능한 중복 [TableView의 행 추가] (http://stackoverflow.com/questions/3496699/addrowen-in-a-tableview) – Stephen