Before I used to allocate and initialize a view controller using initWithNibName, where the parameter for the Nib name is simply the name of the xib/nib file.
However, with the way Xcode/IB works with Storyboards now, I'm not sure what I need to do to initialize a view controller class with it's respective xib/nib.
In my storyboard i have created the view controller and referenced it (from another view controller) and specified it as a Popover type.
Any ideas how this is accomplished?
Thanks.
* Update *
Apple docs says
To identify a specific view controller or segue inside a storyboard,
use Interface Builder to assign it an identifier string that uniquely
identifies it.
But I can't figure out how to assign a unique id via IB. How to do this?
XCode 4.4 and earlier: Identifier;
XCode 4.5: Storyboard ID
STORYBOARD - doesn't contain a view controller with identifier
Related
I am new to the Yii technology, but having worked in IT for many years I hoped I understood generally how software is designed. But the Yii guys have got me good.
I have been trying to understand why I am getting HTTP404 errors.
I have a Win 10 environment using MySQL, with latest versions of MySQL and PHP. I naively assumed that Yii would support the nomenclature standards for objects in the MySQL, especially table names. However it appears I am wrong, so here is a heads up for those interested.
I use all lower case characters for my table names, and where I have a table that is a link between two entities I use a name such as entity1_entity2. I use gii to generate a model from this table and the the CRUD option to generate a basic initial application.
I have the pretty URL active, so the initial URL I use is :
\localhost\Movies\movieactor
Where Movies is the website name defined to IIS (virtual directory) and movieactor is the lowercase name I used for the model and controller objects. The actual name prefix I used was MovieActor for the model and controller objects. I used movieactor for the view sub-directory.
Much to my surprise I was presented with an HTTP404 error message. I spent most of a day trying to understand what I had done wrong.
After a good sleep, I started again the next morning. I decided to try changing the name of the relevant table from movie_actor to movieactor. I then regenerated the model, and CRUD components. This time when I invoked the same URL I was pleasantly surprised to see the web application show me the data.
I have no idea what restrictions the Yii guys place on table names, no documentation that I can find, but this is my experience, and hopefully it may save others some grief.
Have I missed something or is my story correct ?
First of all in Yii there are no requirements for table names. Table or model class names are not directly related to URLs.
When you are using gii to generate model you are prompted to enter the table name. Then the model name is suggested as pascal case version of table name. For example if your table is named movie_actor the suggested model class name will be MovieActor. But you don't have to accept that, you can change it to whatever you want.
Then when you are generating CRUD it asks you to enter model class, search model class and controller class. The model class here is the MovieActor generated earlier. Search model class can be whatever you like, but what is important for URL is the controller class. There is something called controller id based on controller class name. It's a kebab case version of controller class name after removing the Controller suffix. If you name your controller as MovieActorController its controller id will be movie-actor. It's this controller id that you need to use in your url to reach that controller. So, url you have to use for this controller would be \localhost\Movies\movie-actor. You need to use same controller id as a sub-directory for your views too.
When you've decided to change table name to movieactor you've probably also generated the controller as MovieactorController. Because of that its id was movieactor and your url and views subfolder were correct.
I have some data specific to each razor view and and i do not want to hard-code it to each view. So, i want to add view related compile-time data to each view.
Custom attributes do not work for me because we cannot add custom attributes to razor views.
I do not want to re-fetch/populate this data from the data source(dictionary etc.) for each request or when view reached.
So, is there any way to attach data to each view at once throughout the life time of asp.net application?
Note
Actually i want to add scripts/styles generated by webpack for each view statically. Their links include hash values so they change when source scripts/styles change. So, i just want to get them added to each view only once(equivalent to typing them into view) through out the asp.net application, not every time a view loads.
I created a demo application for you here.
You will want to use your appsettings.json file, and inject your settings into your view.
In my appsettings.json I added a section called "ViewConfiguration":
"ViewConfiguration": {
"ExampleKey": "ExampleValue"
}
Your various values will need to go into your ViewConfiguration section.
For example where I have ExampleKey, you will use a generic name like "IndexPageStyleSheet", and where I have ExampleValue, you will need to update each release with the new stylesheet path. This will only need to be updated when the filename changes.
I then created a ViewConfiguration class which stores all of the values from the appsettings.json file.
You will need to create one property per configuration line, and ensure that the name of the property matches the name of the key in your appsettings.json.
For example where my appsettings.json has ExampleKey, my ViewConfiguration class also has an ExampleKey.
public class ViewConfiguration {
public string ExampleKey { get; set; }
}
In your Startup.cs you will need to tell your IOC container to load your configuration values into your configuration object.
In my Startup.cs, my ConfigureServices method loads my "ExampleValue" into ViewConfiguration.ExampleKey automatically.
public void ConfigureServices(IServiceCollection services) {
// This line is the magic that loads the values from appsettings.json into a ViewConfiguration object.
services.Configure<ViewConfiguration>(Configuration.GetSection("ViewConfiguration"));
services.AddMvc();
}
Now, in my _ViewImports.cshtml I inject my ViewConfiguration object so that I don't need to inject it into every single page. This can be anywhere in the _ViewImports.cshtml file. If you only want to inject specific configuration per folder, you can create a new _ViewImports.cshtml file per folder and inject different configuration objects into each one. It's flexible.
#using Microsoft.Extensions.Options;
#* Please rename this variable to something more appropriate to your application: *#
#inject IOptions<ViewConfiguration> InjectedViewConfig
Now, in any page, you can simply reference the property in your ViewConfiguration object.
For example in my Index.cshtml, I reference the ViewConfiguration.ExampleKey property by referencing the strongly typed property on InjectedViewConfig.Value, and it outputs "ExampleValue" on the page.
This value could just as easily be injected into a script or css link tag as the name of a file. It's very flexible.
<h1>Value: #InjectedViewConfig.Value.ExampleKey</h1>
With further research, you will be able to inject these values from any configuration source, such as Azure application settings or Azure Key Vault. Please see this article for more details.
If you are using mvc, you can create models and add it into the views. Since you don't want to recreate for each view, you can create readonly variables.
static readonly MyModel ModelData = new MyModel { PropName = "Hello" };
public IActionResult Index () => View(ModelData);
In your view you can now strongly type the value. If you are looking to use MVVM, you can refer to ViewModel concept still exists in ASP.NET MVC Core?
Implementing IFileProvider and IFileInfo provides changing the contents of view at compile-time. So, we could replace and provide static data in views with a template engine(i.e. http://dotliquidmarkup.org/).
Check this;
https://www.mikesdotnetting.com/article/301/loading-asp-net-core-mvc-views-from-a-database-or-other-location
I have done a RegisterAppStart<FirstViewModel>() in the Core App.cs, now I navigate to FirstViewModel, then SecondViewModel and finally ThirdViewModel using ShowViewModel(),
Is there a way I want to navigate to the viewmodel which has been registered using RegisterAppStart<>(), I mean is this persisted or saved somewhere during run?
All I want is to get this value at runtime.
If you want to use a singleton instance of a view model then you can do this using a custom view model locator - see the wiki - https://github.com/MvvmCross/MvvmCross/wiki/Customising-using-App-and-Setup - "overriding view model location and construction"
I have an Android app which uses a SupportActionBar that contains a bunch of tabs. These tabs each have a fragment that in turn are connected to a ViewModel in my core project. This works great and when i start the app they are all initialized right away and setup correctly.
What i would like to do is to call on a method on one of these ViewModels from my main activity that contains all the tabs and fragments.
I read in another post that in WP you could cast the DataContext to the ViewModel but that might not work in Android. I haven't been able to do this, maybe because my DataContext is not the currently displayed ViewModel but the MainViewModel connected to my main activity. Or maybe it's not supposed to be done that way, i'm not sure.
I'm trying to do this:
var test = (MessagesViewModel)this.DataContext;
test.GetViewDataFromApi();
To update the data in the view when i press the tab. I can't use the Init function for this for example since the ViewModel isn't recreated everytime i show the view.
Are you trying to update some data in the tab's fragment when tab is selected?
If that's the case, one way to do it is to
1) handle the tab selection event to get the current tab(maybe using TabListener),
2) get the fragment (MvxFagment) in the selected tab
3) get the (IMvxViewModel) view-model from the fragment
4) call the method you need to update data on the view-model
I assume you are using a MvxFragment (https://github.com/MvvmCross/MvvmCross/blob/v3.1/Cirrious/Cirrious.MvvmCross.Droid.Fragging/Fragments/MvxFragment.cs?source=cc) so you can access the view-model from the MvxFragment's ViewModel property.
I've got a huge storyboard with lots of views defined. Now I created an additional view (and it's view controller) completely in code. How do I use that new, code-generated view in a storyboard? To make this a little bit more clear: I have three view controllers: A, B and C. A and C are defined via storyboards and work just fine. B is the one I generated in code. How do I wire this up?
I found a quite a few answers—but all of them did only work the other way around.
Thanks!
–f
You can only wire those code-generated view controllers with code too.
Firstly, create the subclass of the viewController, e.g. A and C, that you have in storyboard so that you can modify those view controllers from storyboard with code.
Then, use the navigationController pushViewController:animated: method to push the code-generated view controller, e.g. B or the view controller methods, e.g. A or C, presentViewController:animated:completion: to present the view controller modally.
If you want to push view controllers from storyboard within code-generated view controllers, you can use the storyboard method instantiateViewControllerWithIdentifier:. Just remember to set the Storyboard ID of the view controllers.