網頁

2012年5月22日 星期二

iOS5 push selectedIndex

//for prepareForSegue 
#import "NextPage.h" 


#pragma mark - Segues
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    
    // Make sure we're referring to the correct segue
    if ([[segue identifier] isEqualToString:@"PushNextPage"]) {
        
        // Get reference to the destination view controller
        WordBankVocabulary *vc = [segue destinationViewController];
        
        // get the selected index
        NSLog(@"get the selected index");
        NSInteger selectedIndex = [[self.tableView indexPathForSelectedRow] row];
        
        
        // Pass the name and index of our film
        [vc setSelectedIndex:selectedIndex];
        
        NSLog(@"prepareForSegue: %d",selectedIndex+1);
        
    }
    NSLog(@"prepareForSegue: run");
    
}
NextPage
@interface WordBankVocabulary : UITableViewController
{
      NSInteger selectedIndex;
}

@property (nonatomic) NSInteger selectedIndex;

@synthesize selectedIndex;

#pragma mark - Table view data source
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"CellIdentifier";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
    // Configure the cell...
    NSString *textSelectedIndex =   [[NSString alloc] initWithFormat: @"%d",selectedIndex];

    cell.textLabel.text = textSelectedIndex;
    
    return cell;
}

沒有留言:

張貼留言

注意:只有此網誌的成員可以留言。