![](/img/trans.png)
[英]What is the difference between Modal and Push segue in Storyboards?
[英]Can NOT segue between Storyboards
所以我找到了一個漂亮的輪廓,給了我想要的東西。 但是,我無法切換到其他故事板?
如何通過“內置”窗口進入其他故事板?
包括我的ViewController.M實現文件。 這段代碼似乎自己制作一個表而不是使用故事板(導航控制器)......
如何讓它與其他故事板相媲美?
#import "ViewController.h"
@interface ViewController ()
@end
#define getDataURL @"http://??.??.??.??/phpfile12.php"
@implementation ViewController
@synthesize json, storesArray, myTableView;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName : [UIColor whiteColor]};
[self.navigationController.navigationBar setBackgroundImage:[UIImage new]
forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.shadowImage = [UIImage new];
self.navigationController.navigationBar.translucent = YES;
self.navigationController.view.backgroundColor = [UIColor clearColor];
//set the title
self.title = @"";
[self retrieveData];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - UITableView Datasource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return storesArray.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];
}
//cell.textLabel.text = [NSString stringWithFormat:@"Cell %d", indexPath.row];
//Retrieve the current city object for use with this indexPath.row
Store * currentStore = [storesArray objectAtIndex:indexPath.row];
cell.textLabel.text = currentStore.storeName;
cell.detailTextLabel.text = currentStore.storeAddress;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
#pragma mark - UITableView Delegate methods
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
DetailViewController * dvc = [[DetailViewController alloc]init];
//Retrieve the current selected city
Store * currentStore = [storesArray objectAtIndex:indexPath.row];
dvc.name = currentStore.storeName;
dvc.address = currentStore.storeAddress;
dvc.startDate = currentStore.storeStartDate;
dvc.endDate = currentStore.storeEndDate;
dvc.startTime = currentStore.storeStartTime;
dvc.endTime = currentStore.storeEndTime;
dvc.totalSales = currentStore.storeTotalSales;
dvc.voids = currentStore.storeVoids;
dvc.discounts = currentStore.storeDiscounts;
dvc.guestCount = currentStore.storeGuestCount;
dvc.peopleServed = currentStore.storePeopleServed;
dvc.employeeClockIn = currentStore.storeEmployeeClockIn;
[self.navigationController pushViewController:dvc animated:YES];
}
#pragma mark - Methods
- (void) retrieveData
{
NSURL * url = [NSURL URLWithString:getDataURL];
NSData * data = [NSData dataWithContentsOfURL:url];
json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
//Set up our cities array
storesArray = [[NSMutableArray alloc]init];
for (int i = 0; i < json.count; i++)
{
//Create city object
NSString * sID = [[json objectAtIndex:i] objectForKey:@"id"];
NSString * sAddress = [[json objectAtIndex:i] objectForKey:@"storeAddress"];
NSString * sName = [[json objectAtIndex:i] objectForKey:@"storeName"];
NSString * sStartDate = [[json objectAtIndex:i] objectForKey:@"storeStartDate"];
NSString * sStartTime = [[json objectAtIndex:i] objectForKey:@"storeStartTime"];
NSString * sEndDate = [[json objectAtIndex:i] objectForKey:@"storeEndDate"];
NSString * sEndTime = [[json objectAtIndex:i] objectForKey:@"storeEndTime"];
NSString * sTotalSales = [[json objectAtIndex:i] objectForKey:@"storeTotalSales"];
NSString * sVoids = [[json objectAtIndex:i] objectForKey:@"storeVoids"];
NSString * sDiscounts = [[json objectAtIndex:i] objectForKey:@"storeDiscounts"];
NSString * sGuestCount = [[json objectAtIndex:i] objectForKey:@"storeGuestCount"];
NSString * sPeopleServed = [[json objectAtIndex:i] objectForKey:@"storePeopleServed"];
NSString * sEmployeeClockIn = [[json objectAtIndex:i] objectForKey:@"storeClockIn"];
Store * myStore = [[Store alloc]initWithStoreID: (NSString *) sID andStoreName: (NSString *) sName andStoreStartDate: (NSString *) sStartDate andStoreStartTime: (NSString *) sStartTime andStoreEndDate: (NSString *) sEndDate andStoreEndTime: (NSString *) sEndTime andStoreTotalSales: (NSString *) sTotalSales andStoreVoids: (NSString *) sVoids andStoreDiscounts: (NSString *) sDiscounts andStoreGuestCount: (NSString *) sGuestCount andStorePeopleServed: (NSString *) sPeopleServed andStoreEmployeeClockIn: (NSString *) sEmployeeClockIn andStoreAddress: (NSString *) sAddress];
//Add our city object to our cities array
[storesArray addObject:myStore];
}
[self.myTableView reloadData];
}
@end
要從另一個故事板實例化視圖控制器,您可以使用UIStoryboard storyboardWithName
UIViewController *dvc = [[UIStoryboard storyboardWithName:@"yourStoryboardName" bundle:nil] instantiateViewControllerWithIdentifier:@"yourViewIdentifier"];
[self.navigationController pushViewController:dvc animated:YES];
不過,這是一個更普遍的答案。
我不明白你究竟要求什么,但對於簡單的segue,我使用了這行代碼
[self performSegueWithIdentifier:@"identifier" sender:self];
如果你想在沒有鏈接的情況下進行segue,你必須給視圖控制器提供標識符並使用下面的代碼
UIViewController *homeViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"identifier"];
[self presentViewController:homeViewController animated:0 completion:nil];
我不完全確定你的意思是“Segue to other storyboard”? 以下代碼允許您通過單擊按鈕或其他操作跳轉到同一故事板內的完全不同的視圖控制器樹。
AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *initViewController = [storyboard instantiateViewControllerWithIdentifier:@"SecondScreen"];
delegate.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
delegate.window.rootViewController = initViewController;
[delegate.window makeKeyAndVisible];
Main是您要跳轉到的故事板的名稱。
SecondScreen是視圖控制器的故事板ID。 很可能它是導航或容器。 您需要在身份檢查器下設置“ SecondScreen ”。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.