2014-01-20 27 views
1

所以我完全難倒了這裏。我使用的是xcode 5,我有一個2 segues的表格視圖。我試圖用兩個不同的原型單元來設置賽格,但那不起作用。所以我現在已經在UITableViewController中設置了兩個segues。看起來無論我最後創造的哪個階段都是它所到之處。我沒有收到任何錯誤,並且當我遍歷代碼時,它會在正確的行上觸發以執行segue。UITableViewController與多個segues進入錯誤的視圖

這似乎每次都完美執行,但它只是不去正確的看法。

- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    if([currentTableViewType isEqualToString:@"feedbackOnly"]){ 
     // hits this line correctly 
     [self performSegueWithIdentifier:@"ShowSendFeedback" sender:indexPath]; 
    } else { 
     // hits this line correctly 
     [self performSegueWithIdentifier:@"ShowTicketDetails" sender:indexPath]; 
    } 
} 
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(NSIndexPath *)selectedIndexPath { 
    if ([[segue identifier] isEqualToString:@"ShowTicketDetails"]) 
    { 
     TicketDetailsViewController *tdv = [segue destinationViewController]; 
     NSIndexPath *myIndexPath = [self.tableView indexPathForSelectedRow]; 
     long row = [myIndexPath row]; 
     Ticket * currentTicket = [ticketsArray objectAtIndex:row]; 
     tdv.tPriority = currentTicket.ticketPriority; 
     tdv.tId = currentTicket.ticketId; 
     tdv.tStatus = currentTicket.ticketStatus; 
    } 

    if ([[segue identifier] isEqualToString:@"ShowSendFeedback"]){ 
     FeedbackViewController *fvc = [segue destinationViewController]; 
     NSIndexPath *myIndexPath = [self.tableView indexPathForSelectedRow]; 
     long row = [myIndexPath row]; 
     Ticket * currentTicket = [ticketsArray objectAtIndex:row]; 
     fvc.tPriority = currentTicket.ticketPriority; 
     fvc.tId = currentTicket.ticketId; 
     fvc.tStatus = currentTicket.ticketStatus; 
    } 
} 

要徹底,我已經提供了有問題我的整個控制器。

#import "TicketsViewController.h" 
@interface TicketsViewController() 
@end 
@implementation TicketsViewController 
@synthesize json, ticketsArray, ticketsTableView, currentTableViewType; 

- (id)initWithStyle:(UITableViewStyle)style 
{ 
    self = [super initWithStyle:style]; 
    if (self) { 
     // Custom initialization 
    } 
    return self; 
} 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    self.title = @"Tickets"; 

    AppDataClass *appData=[AppDataClass getInstance]; 
    currentTableViewType = appData.tableViewType; 
    [self retrieveData]; 
} 

- (void)didReceiveMemoryWarning 
{ 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 

#pragma mark - Table view data source 
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    // Return the number of sections. 
    return 1; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    // Return the number of rows in the section. 
    return ticketsArray.count; 
} 

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { 
    if([currentTableViewType isEqualToString:@"feedbackOnly"]){ 
     return @"Requires Feedback"; 
    } else { 
     return @"Issues"; 
    } 
} 

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

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    if(cell == nil){ 
     cell = [[UITableViewCell alloc] initWithStyle: UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]; 
    } 

    Ticket * currentTicket = [ticketsArray objectAtIndex:indexPath.row]; 

    cell.textLabel.text = currentTicket.ticketName; 
    cell.detailTextLabel.text = currentTicket.ticketAddress; 
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 
    if([currentTicket.ticketPriority.lowercaseString isEqualToString:@"high"]) { 
     cell.imageView.image = [UIImage imageNamed:@"alert.png"]; 
     if([indexPath row] % 2) [cell setBackgroundColor:[UIColor lightGrayColor]]; 
    } 
    return cell; 
} 

#pragma mark - Methods 
- (void)retrieveData 
{ 
    // NSURL * url = [NSURL URLWithString:getDataURL]; 
    // NSData * data = [NSData dataWithContentsOfURL:url]; 
    AppDataClass *appData=[AppDataClass getInstance]; 
    NSString *args = @"userid=%@&authid=%@"; 
    NSString *values=[NSString stringWithFormat:args, appData.userId, appData.authId]; 
    json = [appData getPostData:appData.URL_LIST_TICKETS:values]; 

    ticketsArray = [[NSMutableArray alloc] init]; 

    // segeue names 
    // allTickets 
    // feedbackOnly 

    for(int i=0; i<json.count; i++){ 
     NSString * tId = [[json objectAtIndex:i] objectForKey:@"id"]; 
     NSString * tName = [[json objectAtIndex:i] objectForKey:@"name"]; 
     NSString * tPriority = [[json objectAtIndex:i] objectForKey:@"priority"]; 
     Ticket * myTicket = [[Ticket alloc] initWithTicketId:tId andTicketName:tName andTicketPriority:tPriority]; 
     [ticketsArray addObject:myTicket]; 
    } 

    [self.ticketsTableView reloadData]; 

} 

- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    if([currentTableViewType isEqualToString:@"feedbackOnly"]){ 
     [self performSegueWithIdentifier:@"ShowSendFeedback" sender:indexPath]; 
    } else { 
     [self performSegueWithIdentifier:@"ShowTicketDetails" sender:indexPath]; 
    } 
} 

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(NSIndexPath *)selectedIndexPath { 
    if ([[segue identifier] isEqualToString:@"ShowTicketDetails"]) 
    { 
     TicketDetailsViewController *tdv = [segue destinationViewController]; 
     NSIndexPath *myIndexPath = [self.tableView indexPathForSelectedRow]; 
     long row = [myIndexPath row]; 
     Ticket * currentTicket = [ticketsArray objectAtIndex:row]; 
     tdv.tPriority = currentTicket.ticketPriority; 
     tdv.tId = currentTicket.ticketId; 
     tdv.tStatus = currentTicket.ticketStatus; 
    } 

    if ([[segue identifier] isEqualToString:@"ShowSendFeedback"]){ 
     FeedbackViewController *fvc = [segue destinationViewController]; 
     NSIndexPath *myIndexPath = [self.tableView indexPathForSelectedRow]; 
     long row = [myIndexPath row]; 
     Ticket * currentTicket = [ticketsArray objectAtIndex:row]; 
     fvc.tPriority = currentTicket.ticketPriority; 
     fvc.tId = currentTicket.ticketId; 
     fvc.tStatus = currentTicket.ticketStatus; 
    } 
} 

@end 

回答

0

好吧......所以它似乎是XCode中的一個錯誤。我最初複製了第二個ViewController,我試圖繼續並改變它的類以及一些視圖組件。我想StoryBoard足夠聰明,可以重新分配這個觀點。我錯了。 XCode似乎不喜歡那樣。從頭開始使用新的ViewController似乎可以修復所有問題,並且現在可以正常工作。完全相同的代碼工作。

所以,如果有人有這個問題,請確保你沒有複製和粘貼您要Segue公司的視圖控制器。這將節省您的頭痛小時:-)

它可能不得不相同的ViewController這就是爲什麼無論最後SEGUE我的設置是唯一一個工作的參考。

+0

當你複製它會複製視圖控制器的自定義類,如果您設置它的視圖控制器。如果是這樣,那就是你在新的視圖控制器上需要更新的東西。請參閱以下鏈接中的第2步:https://developer.apple.com/library/ios/recipes/xcode_help-interface_builder/articles-storyboard/StoryboardScene.html – Jesse