Conditional use of initWithStyle UITableView - ios6

I have one UITableView class that can load a variety of data. All the actions on the data that is loaded will be the same regardless of what the data is, so I figured it would be best to keep it all in the same class. The problem I'm running into is that for one set of data, I need the UITableView to use the style UITableViewStyleGrouped, and the rest to use UITableViewStylePlain.
I was able to get this to work in prepareForSegue by using the following if statement:
if([whatToLoad isEqualToString:#"Sets"]){
[[segue destinationViewController] initWithStyle:UITableViewStyleGrouped];
}
else
[[segue destinationViewController] initWithStyle:UITableViewStylePlain];
But then Xcode gives me a warning on both of them of "Expression result unused". Is there something else I can do to achieve the same result without the warning? Or do I have to create a different class for the one set of data that needs a grouped table?

You can have multiple table view controllers in the storyboard file, and set the "Class" to the same UITableViewController subclass for each of them. So you can use the same controller code for each of them, but one has a "grouped" table view and the others have a "plain" table view.
Calling
[[segue destinationViewController] initWithStyle:...]
seems risky to me, because the destination view controller is an already allocated and initialized instance, and initXXX functions are generally allowed to return a different instance.

Related

SwiftUI Iterate through all possible Views

In Swift, you have views, views, and more views. and i'm trying to make a dynamic list of views that is varied by the files in a group.
Im aware that the groups are not saved on app creation
I cant use Init() in a view because that implies that the view was activated by an outside source (NavigationView for example)
Having a static variable is saved on app startup so i could probably do something like that.
But Essentially i'm trying to be lazy/clever and do something that you can do in java, like iterate through every class in a package and instantiate those objects as you need. I want a NavigationView that's Dynamic, like i can add an Annotation (attribute in this case, but probably not helpful for my problem, just an ides) to my Views, and have a for loop iterate through an array that contains all my possible view objects and give me a navigationView for that.
I COULD just make a Statically configured list of Views ie [v1(), v2(), v3(), v4()...] and just do a ForEach through that and work that way, i just don't want to have to configure that in the main file when i cold probably do it dynamically (if possible) and just write a new class, and at the top put like an annotation and have it auto add to an Array that i'm managing dynamically.
I know you can iterate through files, but files on compile are not in the same structure (no folders etc...) but even if i could i don't know how to do that, and add all vies to a large Set of views for a navigation pane. Like a ForEach of [arr of views] each becoming a navigation link. and i can get the Name of the View by doing View.name or whatever
TLDR:
I want to have my Views Automatically Add themselves to a Static data list (Array of Views probably) and be able to have a navigationView Dynamically just add it to the clickable NavViews and replace this:
With something that is just a loop of all my possible views that i've declared somehow.
Is this possible? if so how would i go about doing something like this
also, i know its probably not the best idea, but for the sake of learning id like to understand how to do this, then maybe a better way of going about what i want so i don't have a centralized place, and i can make it dynamic

in Entity Framework, DbSet.Local remains out of sync

This one is making me crasy : I have an EF model built upon a database that contains a table named Category with 6 rows in it.
I want to display this in a drop down list in WPF, so I need to bind it to the Categories.Local Observable collection.
The problem is that this observable collection never receives the content of the database table. My understanding is that the collection should get in sync with the database when performing a query or saving data with SaveChanges() So I ran the followin 2 tests :
Categories = _db.Categories.Local;
// test 1
Debug.WriteLine(_db.Categories.Count());
Debug.WriteLine(_db.Categories.Local.Count());
// test 2
_categories.Add(new Category() { CategoryName = "test" });
_db.SaveChanges();
Debug.WriteLine(_db.Categories.Count());
Debug.WriteLine(_db.Categories.Local.Count());
Debug.WriteLine(_categories.Count());
The test 1 shows 6 rows in the database, and 0 in local.
The test 2 shows 7 rows in the database, and 1 in local (both versions)
I also atempted to use _db.Category.Load() but as expected, it doesn't work because it is db first, not code first.
I also went through this page https://msdn.microsoft.com/en-us/library/jj574514(v=vs.113).aspx, created an object-based data source and linked my combo box to it, without success.
Does anyone know what I am doing wrong?
Thank you in advance for your help.
The DbSet<T> class is IQueryable<T>, hence DbSet<T>.Count() method maps to Queryable.Count<T> extension method, which in turn is translated to SQL query and returns the count of the records in the database table without loading anything into db context local cache.
While DbSet<T>.Local simply gives you access to the local cache. It contains the entities that you added as well as the ones being loaded by query that returns T instances (or other entities referencing T via navigation property). In order to fully load (populate) the local cache, you need to call Load:
_db.Categories.Load();
The Load is a custom extension method defined in QueryableExtensions class, so you need to include
using System.Data.Entity;
in order to get access to it (as well as to typed Include, XyzAsync and many other EF extension methods). The Load method is equivalent of ToList but without overhead of creating additional list.
Once you do that, the binding will work. Please note that the Local will not reflect changes made to the database through different DbContext instances or different applications/users.

How to force two instance of the same app (DNN/2sxc) to read from the same stream?

Sorry if my question is silly but I'm new to DNN/2sxc, I've spent the whole day trying to figure this with no success..
I have two instances of the same app, one in the home page and the other on its own page, each one must have its own view template (I use Razor).
My problem is I cannot figure a way to make the two apps read the same data, so every add/edit/remove/re-sort in one of them will be reflected to the other, currently each app has its own data and therefore they are unusable in my case.
I've tried to use a 'EntityTypeFilter' inside a 'Data Query' and use it in both views (as in the News-Simple demo video), it worked and gave me all the items in the two views, but another two problems come with this solution:
1- now I'm unable to use the toolbar to (add/remove/reorder,.. etc) any of the items , as you can see in this image, which is a show-stopper for me,
note: this is the toolbar I use:
#foreach(var item in AsDynamic(Data["Default"]))
{
...
#Edit.Toolbar(target: item, actions: "new,edit,replace,remove,moveup,movedown,instance-list")
2- the 'Content Demo Item' is also visible in the list, but it is not that important since I can delete it and use one of the real data items as a demo item.
I appreciate any kind of help.
Thank you.
So the first thing you should know is the difference when using content-items as data (to query, etc.) and when using it as assigned-items (where each module-instance has a subset of items). Here's the blog that should help you understand the difference: http://2sxc.org/en/blog/post/12-differences-when-templating-data-instead-of-content
So when you want the "manually and easily control the exact items displayed, their ordering etc." you want to use the "content-assigned-to-instance" which also gives you the simple add, delete buttons, as these don't really delete anything, but just remove the assignment from the module-instance.
Now your case is a bit special, in that you want to re-use the exact same set in another module-instance. There are a few ways you can do this:
Same View
if it's exactly the same view etc. just duplicate the module using DNN-features (the add-existing-module-to-another page)
different view
if it's a different view (maybe more compact, etc.) you again have multiple options. The first is to mirror / duplicate using the dnn-feature, and just put an if-im-on-this-page-then-show-differently or inject another CSS. That's probably the easiest without any dev-know-how.
The harder, but possibly nicer way, is to actually to use a new template, and tell it to retrieve the items in the way they are configured in the other module - let's say module 1 is the original, module 2 has a different template wanting to access the items of module 1 in exactly the same order as given in 1. They way to do this is simple, but requires a few lines of C# code in Module 2.
You need to create a new ModuleDataSource (https://2sxc.org/en/Docs/Feature/feature/4542) object and tell it that it's from Module 1. If you've never done this, it's basically that your code can create a query just like the visual designer, but you have more control - see the wiki https://github.com/2sic/2sxc/wiki/DotNet-DataSources-All. The Module-Data-Source in the visual-query-designer doesn't allow you to "switch" modules (a advanced setting we may add in the future) but the object has a ModuleId property which you can set before accessing the data, making it "switch" to that Module. here's the Pseudo code in your Module#2 razor...
var otherModData = CreateSource<ModuleDataSource>();
otherModData.ModuleId = 1;
foreach(var itm in AsDynamic(otherModData["Default"])) {
...
}
That should do it :)

How to use loops in JasperReports .jrxml file?

I am using iReport Designer to design the .jrxml file.
How can I use the for loop or if loop in .jrxml file?
Is it possible?
If yes how?
You may wish to use a scriptlet. It's basically a Java class that extends either of the following two classes:
net.sf.jasperreports.engine.JRAbstractScriptlet
net.sf.jasperreports.engine.JRDefaultScriptlet
In a scriptlet, you can indicate that a certain piece of code should be executed every time a report event occurs, e.g., report, page, or column initialization.
In a scriptlet, you may use loops. You may access fields, parameters, and variable values. You may also adjust variable values.
There is a chapter on scriptlets in the JasperReports Ultimate Guide.
Well what you can do is create a list of selected fields(which client UI selects) and pass it as a collection to JasperFillManager.fillReport and in the jrxml create a field names _THIS which will represent the value's in the List.
And as you want those field to printed in loop, place them in the detail band of the report.

CAKEPHP Do I have to set $this->data in the controller for it to work with the form helper

I would like to set $this->data in a view rather than the controller. Will this work with the form helper to automagically input values?
many thanks!
Further explanation if you really want to know...
You may wonder why I wouldn't just put the values right into the value field but it makes sense in this situation to put it into $this->data; I have a ton of fields of various types and I do not want to have to add if isset() to every value field because form fields are generated based on a stored value and may or may not have already been filled in. I cannot set this->data in the controller because of the data being in JSON. Plus the data has to go through several layers before getting to where it is at this point.
unresolved but I got around it by entering everything manually. It would have been nice to add it automagically.

Resources