2014-02-19 1 views
0

나는 내 웹 사이트에서 데이터를 가져와 Posts을 얻습니다.iOS에서 UITableView의 마지막 행에 문자열이있는 행을 추가하는 방법은 무엇입니까?

내가 JSON 데이터를 20 개 게시 할 때 데이터를 UITableView에 표시합니다. 내 경우

, 난로드 게시물은 "행, 나는 또 다른 새로운 게시물을 보여 내 tableView를 다시로드해야"내가 있음을 누를 때 때문에 "문자열 "Load More Posts.tableView의 마지막에 둘 이상의 행을 추가합니다.

나는 JSON 데이터를 얻을 UITableView에 포스트를 보여 NSMutableArrayNSDictionary을 사용하고 있습니다. 그래서

내가 그것을 어떻게 추가합니까?

+0

iOS 6 이상을 사용하는 경우 UIRefreshControl을 사용할 수 있습니다. 그것은 더 표준적인 방법입니다. – Midas

+0

테이블 뷰에 바닥 글 추가 –

답변

2
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section 
{ 
    UIView *footerView = [[[UIView alloc] init] autorelease]; 
    footerView.backgroundColor = [UIColor clearColor]; 
    footerView.frame=CGRectMake(0, 0, 253,100); 

    UIButton *button = [[UIButton alloc] init]; 
    [button setFrame:CGRectMake(0, 0, 252, 50)]; 
    [button setTitle:@"Load More" forState:UIControlStateNormal]; 
    [button.titleLabel setFont:[UIFont boldSystemFontOfSize:20]]; 
    [button setBackgroundColor:[UIColor clearColor]]; 
    [button.titleLabel setTextColor:[UIColor blackColor]]; 
    [button addTarget:self action:@selector(btn_LoadMore:) forControlEvents:UIControlEventTouchUpInside]; 
    [footerView addSubview:button]; 
    tbl_location.tableFooterView.contentMode = UIViewContentModeScaleToFill; 
    [button release]; 


    return footerView; 
} 

-(IBAction)btn_LoadMore:(id)sender 
{ 
    tbl_location.hidden = TRUE; 

    [self load_json_data]; 
} 
-(void)load_json_data 
{ 
    //some code 

    [tbl_location reloadData]; 
    tbl_location.hidden = FALSE; 
} 
+0

당신은 테이블보기에서 버튼을 추가하고 있습니다 .how 당신은 테이블을 업데이 트합니다 – morroko

+0

@ mokujin 사용 //로드 JsonData /버튼 클릭 이벤트에서 테이블을 다시로드 –

+0

내가 코드로 테스트하면 내 tableView가 끝날 때까지 숨어 있습니다. 데이터 로딩. 데이터로드가 완료되면 UTIableView가 나타납니다. 어떻게해야합니까? –

2

당신은 배열의 레코드 사용자 수에 따라 조건을 처리 manullay 수 있습니다. 다음은 나는 너에게 몇 가지 sa를주고있다.

Array의 레코드를 기반으로 셀의 rown 수를 반환합니다.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
     if ([jsonArray count] == 20) { // Only call the function if we have 20 results in the array OR maintain its counts based on your array counts. 
       if (indexPath.row == [localJsonArray count]) { 
         NSLog(@"Load More requested"); // Add a function here to add more data to your array and reload the content 
       } else { 
         NSLog(@"Normal cell selected"); // Add here your normal didSelectRowAtIndexPath code 
       } 
     } else { 
         NSLog(@"Normal cell selected with < 20 results"); // Add here your normal didSelectRowAtIndexPath code 
     } 
} 
:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
     if ([jsonArray count] < 20) //20 Will change based on your number of records as loop progresses. 
     { 
       return [self.localJsonArray count]; 
     } else { 
       return [self.localJsonArray count] + 1; 
     }  
} 

는 이벤트 처리 유지하고 다른 사람과 추가 ROW 구별 배열에서 셀에 데이터를 입력하고 조건

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
     static NSString *CellIdentifier = @"Cell"; 
     ImageCell *cell = (ImageCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
     if (indexPath.row != [localJsonArray count]) { // As long as we haven’t reached the +1 yet in the count, we populate the cell like normal 
       if (cell == nil) { 
         cell = [[[ImageCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease]; 
       } 
       NSDictionary *itemAtIndex = (NSDictionary *)[self.localJsonArray objectAtIndex:indexPath.row]; 
       [cell setData:itemAtIndex]; 
     } // Ok, all done for filling the normal cells, next we probaply reach the +1 index, which doesn’t contain anything yet 
     if ([jsonArray count] == 20) { // Only call this if the array count is 25 
       if(indexPath.row == [localJsonArray count]) { // Here we check if we reached the end of the index, so the +1 row 
         if (cell == nil) { 
           cell = [[[ImageCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease]; 
         } 
         // Reset previous content of the cell, I have these defined in a UITableCell subclass, change them where needed 
         cell.cellBackground.image = nil; 
         cell.titleLabel.text = nil; 
         // Here we create the ‘Load More Posts.’ cell 
         loadMore =[[UILabel alloc]initWithFrame: CGRectMake(0,0,362,73)]; 
         loadMore.textColor = [UIColor blackColor]; 
         loadMore.highlightedTextColor = [UIColor darkGrayColor]; 
         loadMore.backgroundColor = [UIColor clearColor]; 
         loadMore.font=[UIFont fontWithName:@"Verdana" size:20]; 
         loadMore.textAlignment=UITextAlignmentCenter; 
         loadMore.font=[UIFont boldSystemFontOfSize:20]; 
         [email protected]"Load More Posts..."; 
         [cell addSubview:loadMore]; 
       } 
     } 
     return cell; 
} 

그리고 마지막으로 확인

+0

@이 이유는 무엇입니까? 아무도 내게 알려주 수,이 솔루션은 뭐가 잘못 됐어? 야히코 당신이 코드에서 이것을 시도 했습니까 ... –

+0

미안하지만 나는 외출 중이었습니다. 나는 투표 만하고 투표는 내 것이 아닙니다. 내가 확인 할게. 감사합니다 :) –

관련 문제