2010-09-23 5 views
0

J'ai besoin d'afficher UIWebView sous UITableViewCell lorsque l'utilisateur sélectionne la cellule requise en tapant sur le accessoireButtonTappedForRowWithIndexPath. Par exemple, j'ai trois lignes, Home, Office et History, qui sont affichées dans la vue de table.Comment insérer UIWebView entre UITableViewCells lorsque je tape sur accessoryButtonTappedForRowWithIndexPath?

Si l'utilisateur sélectionne Office, les détails dans le webview devraient s'afficher sous la ligne du bureau ou dans la cellule du bureau.

Si l'utilisateur sélectionne la page d'accueil, les détails de la page Web doivent s'afficher sous la ligne Home ou la cellule Home.

J'espère que vous comprenez mon intention ce que je veux vraiment dire.

Merci, Madan Mohan.

Répondre

0

Vous devrez calculer la position de la cellule par rapport à la vue principale (celle où se trouve votre tableView).

Censé vous avez une hiérarchie comme

mainView 
|--myTable (UITableView*) 
| |--Cell1 
| |--Cell2 
| |--Cell3 
|--myWebView (UIWebView*) 

Il est quelque chose comme

float y = myTable.frame.origin.y+selectedCell.frame.origin.y+selectedCell.frame.size.height; 

myWebView.frame = CGRectMake(myTable.frame.origin.x, y, mainView.bounds.size.width, mainView.bounds.size.height-y) 
+0

Pouvez-vous expliquer plus ... comme la façon d'insérer webView entre les cellules –

+0

Je n'ai pas compris que vous vouliez insérer les webViews entre les cellules mais sous cellules. – VdesmedT

0

Une autre approche

@implementation TableViewController 

-(id) initWithStyle:(UITableViewStyle)style { 
    if (self = [super initWithStyle:style]) { 
     self.editing = NO; 
     selectedCell = -1; 
    } 
    return self; 
} 

- (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 3; 
} 

-(float)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { 
    if (indexPath.row == selectedCell) { 
     return 150.0; 
    } 
    return 50.0; 
} 


// Customize the appearance of table view cells. 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    NSString *CellIdentifier = @"Cell"; 
    if (indexPath.row == selectedCell) { 
     CellIdentifier = @"CustomCell"; 
    } 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     if (indexPath.row == selectedCell) { 
      cell = [[[CellWithWebView alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
     } else { 
      cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
     } 

     cell.selectionStyle = UITableViewCellSelectionStyleGray; 
    } 

    cell.textLabel.text = [NSString stringWithFormat:@"%d", indexPath.row]; 
    cell.detailTextLabel.text = [NSString stringWithFormat:@"%d", indexPath.row]; 
    return cell; 
} 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    selectedCell = indexPath.row; 
    [tableView beginUpdates]; 
    [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:NO]; 
    [tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:NO]; 
    [tableView endUpdates]; 
    [tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone]; 
} 

-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath { 
    selectedCell = -1; 
    [tableView beginUpdates]; 
    [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:NO]; 
    [tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:NO]; 
    [tableView endUpdates]; 
    [tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone]; 
} 
Questions connexes