2016-07-11 1 views
1

행을 선택할 때 어떤 문제가 발생했습니다.Xcode - UITableView 문제

기본적으로 사용자가 UITableViewController 내에서 행을 선택할 때마다 특정 콘텐츠 (주로 텍스트)를 표시하고 싶습니다. 나는이 학위를 가지고있다. 다음 코드를 사용하여 :

var varView = Int() 
if (varView == 0){ 

    Label.text = "E110" 

} 

else { 
    if (varView == 1){ 
    Label.text = "Veyron" 

    } 

    else { 
     Label.text = "Error" 
    } 

} 

이것은 위에서 언급 한대로 작동합니다. 그러나 UITableViewController 내에서 제품을 분류하는 헤더가 있기 때문에 각 섹션 헤더 다음에 "새로 고침"하는 것처럼 보입니다.

그래서

struct Brands { 
    var sectionName : String! 
    var sectionBrands : [String]! 
} 

var brandArray = [Brands]() 


override func viewDidLoad() { 


    brandArray = [ 


    Brands(sectionName: "Bugatti", sectionBrands: ["EB 110","Veyron"]), 

    Brands(sectionName: "Cadillac", sectionBrands: ["Biarritz","BLS", "CTS", "Escalade", "SRX", "STS"]), 

난 그보다 훨씬 더이 같은 UITableVC을 채우는 섹션 헤더 및 텍스트 모두 내있는 UITableViewController를 채우는 배열을 사용했다! 하하.

그러나 사실 나는 Buggati에서 두 줄의 내용 변경 코드가 작동하기 때문에 Cadillac에서 첫 번째 행을 선택할 때 "BLS"를 선택할 때 반송 유형이 "BLS"로 반환됩니다. "Veyron"과 다른 모든 행은 "Error"값을 반환합니다. 첫 번째 행이 "Error"와 함께 반환 된 후에 아무 것도 기대하지 않았지만 언급 한대로 "새로 고침"하는 것으로 보입니다.

은 내가하는 행에 따라 원하는 값 (들)을 반환하기 위해 사용하고있는 코드가 선택되어

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { 
    var DestVC = segue.destinationViewController as! ViewController 

    var indexPath : NSIndexPath = self.tableView.indexPathForSelectedRow! 


    DestVC.varView = indexPath.row 
} 

사람이 문제를 해결하는 방법에 대한 도움이 되거 수 있을까요? 또는 필드의 이름을 사용하여 Integer를 사용하는 것과 반대로 표시되는 것을 결정할 수도 있습니다.

감사합니다.

P.S- 나는 중요하지 않다고 생각하는 SWRevealViewController을 사용하고 있지만 언급할만한 가치가 있다고 생각합니다.

+0

선택한 행이 새보기에서 열려 있습니까? – dreamBegin

+0

행이 선택되면 다른 뷰 컨트롤러가 연속으로 사용됩니다. 그러나 언급 한 바와 같이, 오류는 내가 믿는 코드 내에 있습니다. 셀 식별자를 다시 사용했습니다. 문제가 될 수 있습니까? – TheNoviceProgrammer

+0

도 도움이되지 않습니다. 저는 초보자이기도하지만 NavengationViewContoller를 사용하거나 NavagationViewContoller를 사용하지 않고 새로운 항목을 선택하여 tableViewController를 새 viewController에 열 수있는 방법을 제안 할 수 있습니다. – dreamBegin

답변

0

TableViewController의 경우 ViewController.m에이 함수를 추가하면 View Controller에서 두 메서드를 모두 올바르게 정의해야합니다.

  1. 있는 tableView : cellForRowAtIndexPath :
  2. 있는 tableView : numberOfRowsInSection : 이상

    : -

    (void)tableView:(UITableView *)tableViewdidSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 
    
    
    NSArray *keys=[[NSArray alloc]initWithObjects:@"CellNumberOne",@"CellNumbertwo",@"CellNumberThree",@"CellNumberFour", nil]; 
    NSArray *objects=[[NSArray alloc]initWithObjects:@"1",@"2",@"3",@"4", nil]; 
    
    
    self.myData=[[NSDictionary alloc]initWithObjects:objects forKeys:keys]; 
    
    NSArray *keys=[self.myData allKeys]; 
    
    NSString *cellName=[keys objectAtIndex:indexPath.row]; 
    NSString *detail=[self.myData valueForKey:[keys objectAtIndex:indexPath.row]]; 
    
    if ([email protected]"CellNumberOne") { 
        UIStoryboard *sb=[UIStoryboard storyboardWithName:@"Main" bundle:nil]; 
        UIViewController *view=[sb instantiateViewControllerWithIdentifier:@"CellNumberOne"]; //you have to set identifier for all the view controllers 
        [self.navigationController pushViewController:view animated:YES]; 
        } 
    if ([email protected]"CellNumbertwo") { 
        UIStoryboard *sb=[UIStoryboard storyboardWithName:@"Main" bundle:nil]; 
        UIViewController *view=[sb instantiateViewControllerWithIdentifier:@"CellNumberTwo"]; //you have to set identifier for all the view controllers 
        [self.navigationController pushViewController:view animated:YES]; 
        } 
    
    
    if (cel[email protected]"CellNumberThree") { 
        UIStoryboard *sb=[UIStoryboard storyboardWithName:@"Main" bundle:nil]; 
        UIViewController *view=[sb instantiateViewControllerWithIdentifier:@"CellNumberThree"]; //you have to set identifier for all the view controllers 
        [self.navigationController pushViewController:view animated:YES]; 
        } 
    
    
    if ([email protected]"CellNumberFour") { 
        UIStoryboard *sb=[UIStoryboard storyboardWithName:@"Main" bundle:nil]; 
        UIViewController *view=[sb instantiateViewControllerWithIdentifier:@"CellNumberFour"]; //you have to set identifier for all the view controllers 
        [self.navigationController pushViewController:view animated:YES]; 
        } 
    
    
    
    }