2014-09-24 6 views
0

내 첫 번째 앱을 만드는 중입니다. 내 애플 리케이션 사이드 팝업 메뉴가 나타납니다. 슬라이딩 메뉴 부분을 UITableView로 구현했습니다. 이제 텍스트 옆에 이미지가있는 사이드 메뉴를 채우고 싶습니다. 탭이 있으면 다른보기 컨트롤러를 밀고 싶습니다. 이 작업을 수행하는 가장 좋은 방법은 무엇입니까? 감사합니다사이드 메뉴 바에 항목을 추가하는 방법은 무엇입니까?

+1

가능한 중복 [TableView의 행 추가] (http://stackoverflow.com/questions/3496699/addrowen-in-a-tableview) – Stephen

답변

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

그러나이 코드를 사용하면 테이블을 채울 수 있어야하며 셀을 선택하면 로그가 표시됩니다. 희망이 도움이 :) :

관련 문제