Home > Mobile >  Ios jump web have a problem
Ios jump web have a problem

Time:09-16

Today make an experiment, in the unit click to jump to page, but always collapse to the main
Here are four pages of code
ViewController. H code


# import & lt; UIKit/UIKit. H>

@ interface ViewController: UITableViewController
{
NSArray * curProv;
}
@ property (nonatomic, strong) NSDictionary * provCities;


@ end


ViewController.
m code

# import "ViewController. H"
# import "DetailViewController. H"
@ interface ViewController ()

@ end

@ implementation ViewController
- (NSDictionary *) provCities
{
If (_provCities==nil) {
Nsstrings * fileName=[[NSBundle mainBundle] pathForResource: @ "prov_cities ofType:" @ "plist"].
_provCities=[[NSDictionary alloc] initWithContentsOfFile: fileName];
}
Return _provCities;
}
- (void) viewDidAppear: (BOOL) animated
{
The switch (self. View. The tag) {
Case 2:
CurProv=self. ProvCities [@ "liaoning province"];
The self. The title=@ "information of liaoning province";
break;
Case 3:
CurProv=self. ProvCities [@ "heilongjiang province"];
The self. The title=@ "heilongjiang province information";
break;
Case 1:
CurProv=self. ProvCities [@ "jilin"];
The self. The title=@ "information of jilin province";
break;
Default:
break;
}
NSLog (@ "% @", the self. The title);
NSLog (@ "% @", curProv);
[the self tableView reloadData];
}
- (void) viewDidLoad {
[super viewDidLoad];
//Do any additional setup after loading the view, typically from a nib.
}
- (NSInteger) tableView: (UITableView *) tableView numberOfRowsInSection: (NSInteger) section
{
Return [curProv count];
}
- (UITableViewCell *) tableView: (UITableView *) tableView cellForRowAtIndexPath: (indexPath NSIndexPath *)
{
UITableViewCell * cell=[tableView dequeueReusableCellWithIdentifier: @ "cell"].
NSDictionary * cityDic=[curProv objectAtIndex: indexPath row];
Cell. TextLabel. Text=cityDic [@ "name");
Return the cell;
}
- (void) prepareForSegue segue: (UIStoryboardSegue *) sender: (id) sender
{
If ([segue identifier isEqualToString: @ "city"])
{
DetailViewController * DVC=segue. DestinationViewController;
NSIndexPath * indexPath=self. TableView. IndexPathsForVisibleRows. FirstObject;
NSDictionary * cityDic=[curProv objectAtIndex: indexPath row];
DVC. CityDic=cityDic;
}
}
//- (void) viewDidLoad {
///super viewDidLoad];
////Do any additional setup after loading the view, typically from a nib.
//}


@ end


DetailViewController. H code '


# import & lt; UIKit/UIKit. H>

NS_ASSUME_NONNULL_BEGIN

@ interface DetailViewController: UIViewController
@ property (weak, nonatomic) IBOutlet UIWebView * WebVIew;


@ property (nonatomic, strong) NSDictionary * cityDic;

@ end

NS_ASSUME_NONNULL_END

DetailViewController.
m code
# import "DetailViewController. H"

@ interface DetailViewController ()

@ end

@ implementation DetailViewController

- (void) viewDidLoad {
[super viewDidLoad];
//Do any additional setup after loading the view.
The self. The title=self. CityDic [@ "name");
Nsstrings * urlString=self. CityDic [@ "url");
NSURL * url=[NSURL URLWithString: urlString);
NSURLRequest * request=[NSURLRequest requestWithURL: url];
[the self. The WebVIew loadRequest: request];

}

/*
# pragma mark - Navigation

//In a storyboard - -based application, you will, want to do a little preparation before navigation
- (void) prepareForSegue segue: (UIStoryboardSegue *) sender: (id) sender {
//Get the new view controller using [segue destinationViewController].
//Pass the selected object to the new view controller.
}
*/

@ end

CodePudding user response:

I suggest you in DetailViewController ViewDidLoad a breakpoint, and viewcontrollers prepareForSegue: (UIStoryboardSegue *) segue sender: (id) sender this method also hit a breakpoint, debugging
  •  Tags:  
  • iOS
  • Related