Ios 尝试从具有发起人UITableView的ViewController分离到另一个ViewController
我对iOS编程还是新手,我正在尝试实现一个应用程序,为参加周末黑客大赛的学生显示信息。我目前正在处理一个表格,其中包含赞助商列表,当您单击一个赞助商披露按钮时,我希望它转到另一个页面,该页面仅显示赞助商的名称和包含其网站的web视图 我认为我已经适当地设置了prepareForSegue方法,但当我尝试在iOS模拟器中进行选择时,什么都没有发生。有人能看看我的代码并告诉我是否遗漏了什么吗 SponsorMasterViewController.h文件从这里开始 SponsorDetailViewController.h文件从这里开始Ios 尝试从具有发起人UITableView的ViewController分离到另一个ViewController,ios,objective-c,iphone,uiviewcontroller,segue,Ios,Objective C,Iphone,Uiviewcontroller,Segue,我对iOS编程还是新手,我正在尝试实现一个应用程序,为参加周末黑客大赛的学生显示信息。我目前正在处理一个表格,其中包含赞助商列表,当您单击一个赞助商披露按钮时,我希望它转到另一个页面,该页面仅显示赞助商的名称和包含其网站的web视图 我认为我已经适当地设置了prepareForSegue方法,但当我尝试在iOS模拟器中进行选择时,什么都没有发生。有人能看看我的代码并告诉我是否遗漏了什么吗 SponsorMasterViewController.h文件从这里开始 SponsorDetailVi
我看到您已经在故事板中定义了从masterViewController到DetailViewController的推送序列 要执行此步骤,您需要实现UITableView委托方法,特别是tableView:DidSelectRowatineXpath: PrepareForSegue是为segues做准备,它不执行segues 但是,当您点击“披露详细信息”按钮时,不会发生这种情况,但如果您遵循此实现,则当您点击单元格时会发生这种情况 您应该实施 -voidtableView:UITableView*tableView访问按钮以indexPath:NSIndexPath*indexPath格式显示 有点像
-(void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{
[self performSegueWithIdentifier:@"sponsorSegue" sender:[self.allSponsors objectAtIndexPath: indexPath]];
}
然后把你准备的步骤改成
sponsorDetailController.spon=发送方 啊,我明白了。谢谢你的澄清
#import "SponsorMasterViewController.h"
@interface SponsorMasterViewController ()
@end
@implementation SponsorMasterViewController {
NSArray *allSponsors;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
Sponsor *sponUber = [[Sponsor alloc] init];
sponUber.name = @"Über Operations LLC";
sponUber.url = @"https://www.uberops.com";
Sponsor *sponStar = [[Sponsor alloc] init];
sponStar.name = @"Starbucks";
sponStar.url = @"http://www.starbucks.com";
Sponsor *sponRen = [[Sponsor alloc] init];
sponRen.name = @"Renegade Runner";
sponRen.url = @"https://fsudelivery.com";
Sponsor *sponOEI = [[Sponsor alloc] init];
sponOEI.name = @"Office of Entrepreneurship";
sponOEI.url = @"http://sga.fsu.edu/oei.shtml";
Sponsor *sponJim = [[Sponsor alloc] init];
sponJim.name = @"The Jim Morgan Institute for Global Entrepreneurship";
sponJim.url = @"http://business.fsu.edu/jmi";
Sponsor *sponMail = [[Sponsor alloc] init];
sponMail.name = @"MailChimp";
sponMail.url = @"http://mailchimp.com";
Sponsor *sponGen = [[Sponsor alloc] init];
sponGen.name = @"Genivia";
sponGen.url = @"http://www.genivia.com";
Sponsor *sponFL = [[Sponsor alloc] init];
sponFL.name = @"FLorida IT Career";
sponFL.url = @"https://fitc.cci.fsu.edu";
Sponsor *sponDOMI = [[Sponsor alloc] init];
sponDOMI.name = @"domiventures";
sponDOMI.url = @"http://www.domistation.com";
Sponsor *sponCode = [[Sponsor alloc] init];
sponCode.name = @"Code School";
sponCode.url = @"https://www.codeschool.com";
Sponsor *sponIonic = [[Sponsor alloc] init];
sponIonic.name = @"Ionic Security";
sponIonic.url = @"https://www.ionic.com";
allSponsors = [NSArray arrayWithObjects:sponUber, sponStar, sponRen, sponOEI,
sponJim, sponMail, sponGen, sponFL, sponDOMI, sponCode,
sponIonic, nil];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - TableView Functions
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
//Determine number of sections in my table
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [allSponsors count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *simpleTableIdentifier = @"SponserCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if ( cell == nil ) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
Sponsor *company = [allSponsors objectAtIndex:indexPath.row];
cell.textLabel.text = company.name;
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
return cell;
}
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"sponsorSegue"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
SponsorDetailViewController *sponsorDetailController = (SponsorDetailViewController *)segue.destinationViewController;
sponsorDetailController.spon = [allSponsors objectAtIndex:indexPath.row];
}
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
@end
#import <UIKit/UIKit.h>
#import "Sponsor.h"
@interface SponsorDetailViewController : UIViewController
@property (nonatomic, strong) IBOutlet UILabel *sponsorName;
@property (nonatomic, strong) IBOutlet UIWebView *webView;
@property (nonatomic, strong) Sponsor *spon;
@end
#import "SponsorDetailViewController.h"
@interface SponsorDetailViewController ()
@end
@implementation SponsorDetailViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
//Set the Sponse Label
[self.sponsorName setText:self.spon.name];
//Process sponsor url
NSURL *sponsorURL = [NSURL URLWithString:self.spon.url];
NSURLRequest *request = [NSURLRequest requestWithURL:sponsorURL];
//fit contents of website inside my webview
self.webView.scalesPageToFit = YES;
[self.webView loadRequest:request];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
-(void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{
[self performSegueWithIdentifier:@"sponsorSegue" sender:[self.allSponsors objectAtIndexPath: indexPath]];
}