2012-10-26 4 views
-2

tableview 및 검색 창을 만들었습니다.UITableView 셀에 정확한 세부 정보가 표시되지 않습니다.

셀 1의 이름은 iPhone입니다.

셀 iPhone을 클릭하면 상세보기에서 iPhone에 씁니다. iPod을 검색하면 검색 목록의 첫 번째 셀이되지만이를 클릭하면 iPod 대신 iPhone이 기록됩니다. 여기에 모든 코드를 삽입 해 봅니다.

- (BOOL)shouldAutootateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
    { 
    // Return YES for supported orientations 
    return (interfaceOrientation == UIInterfaceOrientationPortrait); 
     } 

    #pragma mark - Table View Methods 


    - (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView 
{ 


    return 1; 
    } 
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section  { 
    return [displayItems count]; 
     } 


    - (UITableViewCell *)tableView:(UITableView *)aTableView  cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    static NSString *cellIdentifier = @"Cell"; 

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; 
if (!cell) { 
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"]; 
} 


cell.textLabel.text = [displayItems objectAtIndex:indexPath.row]; 


return cell; 

} 

-(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText{ 

if ([searchText length] == 0) { 
    [displayItems removeAllObjects]; 
    [displayItems addObjectsFromArray:allItems]; 

} else { 

    [displayItems removeAllObjects]; 
    for (NSString * string in allItems){ 
     NSRange r =[string rangeOfString:searchText options:NSCaseInsensitiveSearch]; 

     if (r.location != NSNotFound){ 
      [displayItems addObject:string]; 
     } 
    } 

    [tableView reloadData]; 

    } 

    } 





    -(void)searchBarSearchButtonClicked:(UISearchBar *)asearchBar { 

    [searchBar resignFirstResponder]; 



     } 


    - (UITableViewCellAccessoryType)tableView:(UITableView *)tableView accessoryTypeForRowWithIndexPath:(NSIndexPath *)indexPath{ 
return UITableViewCellAccessoryDisclosureIndicator; 
    } 


     - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 



     { 
    DetailViewController *DVC = [[DetailViewController alloc] init]; 

    //Pass the row to the DVC 


DVC.characterNumber = [indexPath row]; 

//Push the DetailViewController object onto the stack 

[self.navigationController pushViewController:DVC animated:YES]; 



} 
@end 
+0

우리는 필요 조금 더 자세히. didSelectRowAtIndexPath에서 사용중인 코드를 게시하고 Storyboards를 사용하는 경우 구현 한 prepareForSegue 메서드가 필요합니다. –

+0

코드로 주제를 편집했습니다 – ffds

답변

1

당신은 allItems 배열에 대한 세부 컨트롤러 행 번호에 전달하는,하지만 displayItems에

DVC.characterNumber = [indexPath row]; 

당신이 allItems 배열하지 displayItems 배열

에서 올바른 행을 assing해야 있다는 것을 동일하지 않습니다

업데이트 :

NSString *item = [displayItems objectAtIndex:indexPath.row; 
DVC.characterNumber = [allItems indexOfObject:item]; 
+0

코드를 작성하여 여기에 업로드 할 수 있습니까? – ffds

+0

답변이 업데이트되었습니다. – NeverBe

관련 문제