2011-12-22 3 views
0

질문이 2 개 있습니다.테이블 뷰 및 단추 추가

1.) 저는 tableView를 가지고 있으며, 100 개가 넘는 행 (데이터)을 갖습니다. 하지만 한 번에 10 개의 레코드 만 표시합니다. 사용자가 아래로 스크롤하면 10 행 아래에 load the next 10 recordsload the previous 10 records이라는 버튼을 추가하려고합니다. 이 단추를 어떻게 추가합니까? 참고 : 테이블보기의 마지막 레코드로 스크롤 할 때이 버튼 만 나타나는 내가 화살표 모양 (As a Navigation button)

을 가지고 그 두 버튼이 필요

2) (I 너무 iTunes에서 비슷한 예를 찾을 수 없음)

어떻게해야합니까? 프로그래밍 방식으로. (이 인터페이스 빌더를 사용하여 만들지 않습니다)

+0

어디서 버튼을 원하십니까? 10 행이 표시된 후 – Ariel

+0

이 표시됩니다. – Illep

+0

그런 다음 그 버튼이있는 행을 하나 더 추가하면됩니다 ... – Ariel

답변

1

이 단계와 코드를 사용하십시오.

1)있는 UIButton

3) 대상을 추가하기위한 버튼을

2) 배경 이미지를 만들 (getNext10List)

4) 작성 글보기

5)에서보기를 추가하여 세포.

UIButton *pagingButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
    pagingButton.frame = CGRectMake(0, 5, 316, 35); 
    pagingButton.backgroundColor = [UIColor clearColor]; 
    UIImage *buttonImageNormal = [UIImage imageNamed:@"[email protected]"]; 
    [pagingButton setBackgroundImage:buttonImageNormal forState:UIControlStateNormal]; 
    [pagingButton addTarget:self action:@selector(getNext10List) forControlEvents:UIControlEventTouchUpInside]; 

    //create a footer view on the bottom of the tabeview 
    footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 316, 45)]; 
    [footerView addSubview:pagingButton]; 

    messageTableView.tableFooterView = footerView;  
    [[self view] addSubview:messageTableView]; 
+0

그래서 이러한 코드를 ViewDidLoad 메서드에 추가해야합니까? 나는 2 개의 단추가 있어야하므로 다른 단추를 만들어'messageTableView'에 추가해야합니까? 여기에 'UINavigationButton' 모양의 버튼이 필요합니다. 어떻게해야합니까? (이 질문에 대한 미안, 나는 초보자입니다) – Illep

+0

10 행 셀을로드 한 다음 테이블 뷰를 다시로드하면이 코드를 추가 할 수 있습니다. 데이터로드가 끝나면이 코드를 추가합니다. 나는 실제 페이지 카운트를 알려주는 깃발을 가지고 있습니다. 더 이상 데이터를 가지고 있지 않다면 removeFromSuperview 단추와 tablefotterview를 사용하십시오. – AAV

+0

데이터가 'cellForRowAtIndexPath' 메서드의 셀에 채워지므로 모든 데이터가 채워지면 위 코드를 추가해야합니까? 어떤 방법으로 붙여야합니까?('cellForRowAtIndexPath' 다음에 해고당하는 메소드는 무엇입니까? 그걸 추가해야합니까?) – Illep

0

행 11이면 하위보기에 단추가있는 하위보기가 셀의 contentView에 있습니다.

+0

어떻게해야합니까? 표시 할 레코드가 충분하지 않은 경우 (레코드가 3 개있는 경우 4 번째 행에 버튼을 추가해야한다고 말합니다). 가능한 경우 샘플 코드를 제공 할 수 있습니까? – Illep

1

사용자 지정 UITableViewCell 하위 클래스가 필요합니다. 뭐 그런 :

.H 파일 :

#define kBackButtonPressedNotification @"kBackButtonPressedNotification" 
#define kForwardButtonPressedNotification @"kForwardButtonPressedNotification" 

@interface ButtonsTableViewCell : UITableViewCell { 
@private 
    UIButton* _backButton; 
    UIButton* _forwardButton; 
} 
@end 

하는 .m 파일 :

@implementation ButtonsTableViewCell 
-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{ 
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; 
    if(self){ 
     _backButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
     _backButton.frame = CGRectMake(10, 10, 100, 30); //put numbers that are good for you 
     [_backButton setImage:[UIImage imageNamed:@"someBackButtonImage.png"] forState:UIControlStateNormal]; 
     [_backButton addTarget:self action:@selector(backPressed) forControlEvents:UIControlEventTouchUpInside]; 
     [self.contentView addSubview:_backButton]; 

     _forwardButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
     _forwardButton.frame = CGRectMake(10, 10, 100, 30); //put numbers that are good for you 
     [_forwardButton setImage:[UIImage imageNamed:@"someForwardButtonImage.png"] forState:UIControlStateNormal]; 
     [_forwardButton addTarget:self action:@selector(forwardPressed) forControlEvents:UIControlEventTouchUpInside]; 
     [self.contentView addSubview:_forwardButton]; 
    } 
    return self; 
} 

-(void)backPressed{ 
    [[NSNotificationCenter defaultCenter]postNotificationName:kBackButtonPressedNotification object:nil]; 
} 

-(void)forwardPressed{ 
    [[NSNotificationCenter defaultCenter]postNotificationName:kForwardButtonPressedNotification object:nil]; 
} 
@end 

행 + 1의 컨트롤러의 -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section; 방법 반환 번호에 (추가 행 버튼). -(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;에서 indexPath.row를 확인하고 마지막 사용자 인 경우 해당 맞춤 셀의 인스턴스를 반환합니다.

-(void)viewWillAppear:(BOOL)animated{ 
    [super viewWillAppear:animated]; 
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(yourBackMethod) name:kBackButtonPressedNotification object:nil]; 
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(yourForwardMethod) name:kForwardButtonPressedNotification object:nil]; 
} 

-(void)viewWillDisappear:(BOOL)animated{ 
    [super viewWillDisappear:animated]; 
    [[NSNotificationCenter defaultCenter]removeObserver:self]; 
} 

yourBackMethodyourForwardMethod에 대한 적절한 구현을 제공하는 것을 잊지 마세요 : 그리고 물론 당신의이 같은 말을하자, 그 알림을 등록해야합니다.

관련 문제