gpt4 book ai didi

ios - 在 UIView Controller 和 UITableViewController 之间传递值

转载 作者:行者123 更新时间:2023-11-29 02:50:27 26 4
gpt4 key购买 nike

我是 iOS 及其开发的新手。我正在开发 iPhone 应用程序。那里有 UITableView 和 UIWebView。当我按下 UITableview 的单元格时,根据点击那里我想在我的 UIWebView 中加载各种网页。为此,我必须将字符串链接从 EssentialViewController 传递到 DeatailViewController。我收到了错误。请帮助我。

错误日志

2014-07-07 07:09:53.511 WADTourisum[564:60b] -[UINavigationController currentActiveNVC]: unrecognized selector sent to instance 0x8e9b650
2014-07-07 07:09:53.514 WADTourisum[564:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UINavigationController currentActiveNVC]: unrecognized selector sent to instance 0x8e9b650'
*** First throw call stack:
(
0 CoreFoundation 0x01a421e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x0158f8e5 objc_exception_throw + 44
2 CoreFoundation 0x01adf243 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x01a3250b ___forwarding___ + 1019
4 CoreFoundation 0x01a320ee _CF_forwarding_prep_0 + 14
5 WADTourisum 0x00002c9b -[AMSlideMenuContentSegue perform] + 171
6 UIKit 0x007b3f0c -[UIStoryboardSegueTemplate _perform:] + 174
7 UIKit 0x0037041c -[UIViewController performSegueWithIdentifier:sender:] + 72
8 WADTourisum 0x00013b03 -[Essentialinfocontroller tableView:didSelectRowAtIndexPath:] + 179
9 UIKit 0x003399a1 -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 1513
10 UIKit 0x00339b14 -[UITableView _userSelectRowAtPendingSelectionIndexPath:] + 279
11 UIKit 0x0033e10e __38-[UITableView touchesEnded:withEvent:]_block_invoke + 43
12 UIKit 0x0026d0aa ___afterCACommitHandler_block_invoke + 15
13 UIKit 0x0026d055 _applyBlockToCFArrayCopiedToStack + 403
14 UIKit 0x0026ce76 _afterCACommitHandler + 532
15 CoreFoundation 0x01a0a36e __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
16 CoreFoundation 0x01a0a2bf __CFRunLoopDoObservers + 399
17 CoreFoundation 0x019e8254 __CFRunLoopRun + 1076
18 CoreFoundation 0x019e79d3 CFRunLoopRunSpecific + 467
19 CoreFoundation 0x019e77eb CFRunLoopRunInMode + 123
20 GraphicsServices 0x03a365ee GSEventRunModal + 192
21 GraphicsServices 0x03a3642b GSEventRun + 104
22 UIKit 0x0024ff9b UIApplicationMain + 1225
23 WADTourisum 0x000046fd main + 141
24 libdyld.dylib 0x02089701 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)

EssetialViewController.h

import <UIKit/UIKit.h>
#import "DetailViewController.h"

@interface Essentialinfocontroller : UIViewController<UITableViewDataSource,UITableViewDelegate>

@property (weak, nonatomic) IBOutlet UITableView *info;
@property (nonatomic,strong) NSDictionary * courses;
@property (nonatomic, strong)NSArray *coursekeys;

@property (nonatomic,retain)IBOutlet DetailViewController * myWebview;

@property(nonatomic,strong) NSString* customeLink;

@end

EssetialViewController.m

#import "Essentialinfocontroller.h"
@interface Essentialinfocontroller ()
@end
@implementation Essentialinfocontroller
@synthesize myWebview;
@synthesize courses;//dictionary type object
@synthesize coursekeys; //array type object
@synthesize customeLink;
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *myfile= [[NSBundle mainBundle]pathForResource:@"essentialinfo" ofType:@"plist"];

// NSLog(@"testing path %@",myfile);

courses=[[NSDictionary alloc]initWithContentsOfFile:myfile];

coursekeys =[courses allKeys];

}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [courses count];
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell * cell=[[ UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];

NSString * currentCourseName =[coursekeys objectAtIndex:[indexPath row]];

[[cell textLabel]setText:currentCourseName];

cell.accessoryType =UITableViewCellAccessoryDisclosureIndicator;

return cell;
}

//implement stack method

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




if(indexPath.row==0){

[self performSegueWithIdentifier:@"segue" sender:self];//**Error is here**


UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];

UIViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"story"];

customeLink=@"https://www.facebook.com/";



[self.navigationController pushViewController:viewController animated:YES];


}
if (indexPath.row==1) {
NSLog(@"myUrl-->2 ");

}



}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Make sure your segue name in storyboard is the same as this line
if ([[segue identifier] isEqualToString:@"segue"])
{

DetailViewController *vc = [segue destinationViewController];

vc.link=customeLink;
}
}

//end

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];

}

@end

DetailViewController.h

#import <UIKit/UIKit.h>

@interface DetailViewController : UIViewController

@property (weak, nonatomic) IBOutlet UIWebView *info;

@property(strong,nonatomic)NSString * link;

@end

DetailViewController.m

#import "DetailViewController.h"

@interface DetailViewController ()

@property(nonatomic,weak)NSString *customelink;
@end

@implementation DetailViewController

@synthesize info;

@synthesize link;

@synthesize customelink;

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

- (void)viewDidLoad
{
[super viewDidLoad];
self.customelink=self.link;


NSLog(@"link--> %@",self.customelink);

NSURL *url= [NSURL URLWithString:customelink];
NSURLRequest * requestURL= [NSURLRequest requestWithURL:url];
[info loadRequest:requestURL];


}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];

}

@end

My Segue image

enter image description here

最佳答案

didSelectRowAtIndexPath

- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
if(indexPath.row==0)
{
[self performSegueWithIdentifier:@"segue" sender:self];
}
}

prepareForSegue

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Make sure your segue name in storyboard is the same as this line
if ([[segue identifier] isEqualToString:@"segue"])
{
DetailViewController *vc = [segue destinationViewController];
vc.link=@"https://www.facebook.com/";
}
}

关于ios - 在 UIView Controller 和 UITableViewController 之间传递值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24602057/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com