2013-01-08 14 views
0

我試圖連接表格視圖中的每個單元格必須在網絡視圖中與不同的網頁連接,並且我還使用了導航控制器。表格視圖中的每個單元格都必須連接到IOS中的不同網頁

這是maincontroller.m文件

`-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section  
    { 
     return [self.settle count]; 
    } 
       -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:   (NSIndexPath *)indexPath 
    {   
      static NSString *simpletableidentifier = @"tcell"; 
     UITableViewCell *cell = [tableView  dequeueReusableCellWithIdentifier:simpletableidentifier]; 
    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpletableidentifier]; 
    } 

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


} 
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 
if ([segue.identifier isEqualToString:@"show"]) { 
    NSIndexPath *indexPath=self.tableView.indexPathForSelectedRow; 
     website *destViewController = segue.destinationViewController; 
       destViewController.web = [settle objectAtIndex:indexPath.row]; 

    switch (indexPath.row) { 
     case 0: 
      [email protected]"http//www.google.com"; 
      break; 

     case 1: 
      [email protected]"http//www.yahoo.com"; 
      break; 

     default: 
      break; 
    } 
    } 
` 

,並在另一個視圖控制器文件中所有的

@implementation website 
@synthesize web; 
@synthesize u; 
//@synthesize recipeLabel; 
//@synthesize recipeName; 
- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Add code to load web content in UIWebView 
    { 


      NSURL *url = [NSURL URLWithString:@"u"]; 


      NSURLRequest *request = [NSURLRequest requestWithURL:url]; 
      [web loadRequest:request]; 

} 

回答

0

首先,你不需要爲每個單元單獨的UIWebView對象。 單個Webview可用於加載不同的URL。

爲了解決烏爾問題 在viewDidLoad方法,正確地創建URL對象作爲

(void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    NSURL *url = [NSURL URLWithString:self.u]; 

    NSURLRequest *request = [NSURLRequest requestWithURL:url]; 
    [web loadRequest:request]; 
} 

和給予適當的URL格式等@"http://www.google.com/

相關問題