I am currently populating a TableView's cells with static data.
For ex.
- (void)viewDidLoad
{
[super viewDidLoad];
_carNamesArray = #[#"Porsche", #"Ferrari", #"Fiat"];
}
Can someone point me at an example that would show me how to load the data from a SQLite database instead?
Thanks.
Here is a tutorial- 'How To Develop an iPhone or iPad App using SQLite Data and an UITableView | iOS |'.
Hope it'll help you.
Related
Hi I am a newbie in CodenameOne am now creating a eCommerce app using CodenameOne resource editor ,I have used multilist for displaying products . I have checked the checkbox feature wherein I got the checkbox for all my items .My question here is by code in statemachine how do I get the name of product checked by the user and how to get whether the checkbox is checked or not .I tried implementing findMultiList().getSelected() but it returns always true if I check r uncheck.
Please help me also it would be great if you could tell me how to integrate google drive in my project because I need to pull data from excel sheet and populate it in the list.
You need to get the model and traverse the elements within it:
ListModel<Map<String, Object>> model = (ListModel<Map<String, Object>>)findMultiList(c).getModel();
ArrayList<Map<String, Object>> items = new ArrayList<>();
for(int iter = 0 ; iter < model.getSize() ; iter++) {
Map<String, Object> current = model.getItemAt(iter);
String checked = (String)current.get("emblem");
if(checked != null && "true".equals(checked)) {
items.add(current);
}
}
I haven't tried this code but it should work. Notice that the name "emblem" is the default name used for the MultiButton/MultiList but you can change it to be anything.
You can place a break point on the for loop and inspect the map elements as you traverse them to see how this works.
Codename One doesn't have dedicated support for google drive api yet...
However, it does support Firebase (noSQL, so no table type data)
THis means you'll have to work with variable pairs.
There are resources for table databases, though :
https://www.codenameone.com/javadoc/com/codename1/db/Database.html
check out these libraries
https://github.com/shannah/cn1-data-access-lib
(Accessing data from web, sqlite support)
https://github.com/jegesh/cn1-object-cacher
(cache from web db)
These resources should help; good luck with your development :)
I'm trying to figure out how to populate a table from a JSON array. So far, I can populate my table cells perfectly fine by using the following code:
self.countries = [[NSArray alloc]initWithObjects:#"Argentina",#"China",#"Russia",nil];
Concerning the JSON, I can successfully retrieve one line of text at a time and display it in a label. My goal is to populate an entire table view from a JSON array. I tried using the following code, but it still won't populate my table. Obviously I'm doing something wrong, but I searched everywhere and still can't figure it out:
NSURL *url = [NSURL URLWithString:#"http://BlahBlahBlah.com/CountryList"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON)
{
NSLog(#"%#",[JSON objectForKey:#"COUNTRIES"]);
self.countries = [JSON objectForKey:#"COUNTRIES"];
}
failure:nil];
[operation start];
I am positive that the data is being retrieved, because the NSLog outputs the text perfectly fine. But when I try setting my array equal to the JSON array, nothing happens. I know the code is probably wrong, but I think I'm on the right track. Your help would be much appreciated.
EDIT:
This is the text in the JSON file I'm using:
{
"COUNTRIES": ["Argentina", "China", "Russia",]
}
-Miles
It seems that you need some basic JSON parsing. If you only target iOS 5.0 and above devices, then you should use NSJSONSerialization. If you need to support earlier iOS versions, then I really recommend the open source JSONKit framework.
Having recommended the above, I myself almost always use the Sensible TableView framework to fetch all data from my web service and automatically display it on a table view. Saves me a ton of manual labor and makes app maintenance a breeze, so it's probably something to consider too. Good luck!
This must be something very simple, I just don't see it (and can not find the answer :(
I am trying to learn DevExpress controls and have read that eXpress Persistent Objects is recommended for O/R mapping.
1) I have an existing SQL Server Compact 4.0 database for which I generated ORM
2) I have a Winform with XtraGrid.GridControl gridControl1
3) In Form_Load event I have this code:
XPCollection cName = new XPCollection(typeof(WindowsFormsApplication1.DUzskv1r6.XPO_TableName));
int c = cName.Count; //didn't help...
cName.DisplayableProperties = "Name;Nr"; //choose columns to display
gridControl1.MainView.PopulateColumns();
gridControl1.DataSource = cName;
I have read that it using "delayed loading" - loading when it is necessary (http://documentation.devexpress.com/#XPO/clsDevExpressXpoXPCollectiontopic), but reading XPcollections record Count didn't do the trick as it was suggested.
As a result I get an empty gridControl1 with columns "Name" and "Nr".
Please help - what am I missing?
I think the issue is somewhere in your datalayer initialization.
You use XPCollection with default session, maybe you forgot to initialize it.
The best way is to specify the session is in the XPCollection contractor.
I've tried to get this app going but I don't know how to go about it. I have tried googling for days getting a good answer but to no avail. Therefor I turn to you.
I want to have a typical database (sql or core data) with all data collected. Then display first criteria in a tableview, pass data to next tableview, and in the third tableview display cells depending on the two choices made previously (like: where (x=1 & y=2) then display cells ). Finally get a detailview where I can load optional data from the database.
Any which way you can help or point me in any direction would be great.
//KeLLoGsX
RayWenderlich Tutorials has a number of tutorials that might apply.
More specifically, when a user selects a row in a view use the prepareForSegue method to set a property on the new view indicating the selection so you can taylor the new view accordingly. For example:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"editTemplate"]) {
[[segue destinationViewController] setManagedObjectContext:self.managedObjectContext];
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
self.selectedTemplate = [self.fetchedResultsController objectAtIndexPath:indexPath];
[[segue destinationViewController] setSelectedTemplate:self.selectedTemplate];
}
if ([[segue identifier] isEqualToString:#"returnToNotes"]) {
// do nothing special
}
}
The segue identifier like "editTemplte" are set in storyboard by selecting the segue and using the attributes inspector to name them.
I'm building an iPhone application, where I have a table view with items that can be checked on or off. When the user has checked the selected items, I have to send that information back to my server. However, I don't know the optimal way to do this. Should I load the information into an array? Maybe a dictionary? And can you give specific examples of how to do this with code?
Thanks.
No one?
Update
To be clear, everything regarding URL connections is taken care of. All I need is a way to sort the information in an array or the like, where the index path of the items is used to represent the checked table view cells. After that, I'll convert the information to JSON, which I will then parse on the server. I have a JSON encode/decode library, so I don't need any information on how to do that.
OK, this seems to solve my problem. If someone knows a more elegant solution, please let me know.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if ([self.tableView cellForRowAtIndexPath:indexPath].accessoryType == UITableViewCellAccessoryCheckmark) {
[self.tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryNone;
[self.tableView cellForRowAtIndexPath:indexPath].textLabel.textColor = [UIColor colorWithRed:0.0 / 255 green:0.0 / 255 blue:0.0 / 255 alpha:1];
[selectedSources removeObject:[NSNumber numberWithInt:indexPath.row]];
} else {
[self.tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryCheckmark;
[self.tableView cellForRowAtIndexPath:indexPath].textLabel.textColor = [UIColor colorWithRed:72.0 / 255 green:104.0 / 255 blue:152.0 / 255 alpha:1];
[selectedSources addObject:[NSNumber numberWithInt:indexPath.row]];
}
[self.tableView deselectRowAtIndexPath:indexPath animated:YES];
}
selectedSources is an NSMutableArray, which I then JSON encode and send to my server. Based on the index path, I can then identify which table view cells have been checked/unchecked server side.
Thanks, Anna!