2013-08-02 2 views
0

Это код, который у меня до сих пор, в основном, что должно произойти, так это то, что как только вы сделаете выбор в UITableView, вы должны получить переход, который приведет вас к UIWebView, хотя все, что происходит, выбор, который он выделяет только синим цветом.UITableView с UIWebView не загружает UIWebView. Требует ли IBAction?

Первый контроллер представления .h

#import <UIKit/UIKit.h> 

@interface YoMaFifthViewController : UITableViewController 

{ 

NSArray *data, *sites; 
} 


@end 

Первый контроллер представления .m

#import "YoMaFifthViewController.h" 
#import "YoMaWebsiteViewController.h" 

@interface YoMaFifthViewController() 

@end 

@implementation YoMaFifthViewController 



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

} 

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

} 

#pragma mark - view lifecycle 

- (void)viewDidLoad 
{ 
[super viewDidLoad]; 

data = [NSArray arrayWithObjects:@"Website", @"Developer", nil]; 
sites = [NSArray arrayWithObjects: 
     @"https://www.google.co.uk/", 
     @"https://www.google.co.uk/", 
     nil]; 


// Uncomment the following line to preserve selection between presentations. 
// self.clearsSelectionOnViewWillAppear = NO; 

// Uncomment the following line to display an Edit button in the navigation bar for this view controller. 
// self.navigationItem.rightBarButtonItem = self.editButtonItem; 
} 


#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 [data count]; 
} 

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

// Configure the cell... 

cell.textLabel.text = [data objectAtIndex:indexPath.row]; 
cell.detailTextLabel.text = [sites objectAtIndex:indexPath.row]; 
cell.imageView.image = [UIImage imageNamed:[data objectAtIndex:indexPath.row]]; 
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 
return cell; 





} 

/* 
// Override to support conditional editing of the table view. 
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
// Return NO if you do not want the specified item to be editable. 
return YES; 
} 
*/ 

/* 
// Override to support editing the table view. 
- (void)tableView:(UITableView *)tableView commitEditingStyle:  (UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
if (editingStyle == UITableViewCellEditingStyleDelete) { 
    // Delete the row from the data source 
    [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade]; 
} 
else if (editingStyle == UITableViewCellEditingStyleInsert) { 
    // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view 
} 
} 
*/ 

/* 
// Override to support rearranging the table view. 
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath 
{ 
} 
*/ 

/* 
// Override to support conditional rearranging of the table view. 
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
// Return NO if you do not want the item to be re-orderable. 
return YES; 
} 
*/ 

#pragma mark - Table view delegate 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 

{ 
YoMaWebsiteViewController *wvc = [[YoMaWebsiteViewController alloc] initWithNibName:@"YoMaWebsiteViewController" bundle:nil]; 
wvc.site = [sites objectAtIndex:indexPath.row]; 
[self.navigationController pushViewController:wvc animated:YES]; 

} 




@end 

Сайт контроллер представления .h

#import <UIKit/UIKit.h> 

@interface YoMaWebsiteViewController : UIViewController 
{ 

IBOutlet UIWebView *webview; 

} 

@property (retain) NSString *site; 


@end 

Сайт-контроллер .m

#import "YoMaWebsiteViewController.h" 

@interface YoMaWebsiteViewController() 

@end 

@implementation YoMaWebsiteViewController 
@synthesize site; 

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
if (self) { 
    // Custom initialization 
} 
return self; 
} 

- (void)viewDidLoad 
{ 
[super viewDidLoad]; 

NSURL *url = [NSURL URLWithString:self.site]; 
NSURLRequest *request = [NSURLRequest requestWithURL:url]; 
[webview loadRequest:request]; 

// Do any additional setup after loading the view from its nib. 
} 

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

@end 
+0

Ваш стол просмотреть контроллер внутри контроллера навигации? Установите контрольную точку в файле didSelectRowAtIndexPath и проверьте значение self.navigationController. Держу пари, что это ноль. – jsd

ответ

0

Вы бы нужен Action IB или SEGUE к контроллеру представления веб-сайт (для статических ячеек). Когда дело доходит до динамических прототипов, segues будет работать. Вы можете сделать segues с небольшим количеством кода. Сначала перейдите в раскадровку и нажмите Управление - от контроллера Первого взгляда до контроллера просмотра веб-сайта (используйте значки внизу или используйте контур документа). Затем, после того, давая SEGUE идентификатор, используйте следующий код:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    [self performSegueWithIdentifier:@"yourSegueIdentifier" sender:[self.tableView cellForRowAtIndexPath:indexPath]]; 
} 

Edit 2: Если вы не используете XIB это сделать (без контроля сопротивления):

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    [self.navigationController pushViewController:viewControllerNameHere animated:YES sender:[self.tableView cellForRowAtIndexPath:indexPath]]; 
} 
+0

Я не использую раскадровки, я использую .xib's – user2604675

+0

Просто используйте это: '[self presentModalViewController: otherViewCon animated: YES];' –

+0

Где я должен реализовать это в своем коде? – user2604675

Смежные вопросы