我在将字符串传递给另一个 UIViewController 然后打开这个 UIViewController 时遇到问题,这就是我所做的:
。H
#import <UIKit/UIKit.h>
@interface BroswerViewController : UIViewController
@property (retain, nonatomic) IBOutlet UIWebView *myBrowserView;
@property (nonatomic, retain) NSString * myString;
@end
.m
@implementation BroswerViewController
@synthesize myBrowserView;
@synthesize myString;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewWillAppear:(BOOL)animated {
myString = [myString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://mywebsite/%@",myString]];
NSLog(@"%@",url);
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[myBrowserView loadRequest:request];
}
我称之为类:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (!self.myBroserViewController) {
self.myBroserViewController = [[[BroswerViewController alloc] initWithNibName:@"BroswerViewController" bundle:nil] autorelease];
}
[self.myBroserViewController setMyString:[NSString stringWithString:[stringArray objectAtIndex:indexPath.row]]];
[self.navigationController pushViewController:self.myBroserViewController animated:YES];
}
好的,所以我将一个字符串传递给 BrowseViewController 类,然后打开 browseviewcontroller 类并使用我传递的字符串打开 url,第一次总是工作,然后我返回并传递另一个字符串并打开视图和第二次随机工作,第三次永远不会,我总是在线收到 EXC_BAD_ACCESS
@synthesize myString;
我不知道我错了什么...