I create and save the different names of the buttons in a plist file as an array ....
var newSpecificationTitleTextField: UITextField?
var specs : [String]
data?.setValue(self.specs, forKey: "NameButton")
and everything is fine until I create my button from scratch since my array is updated .....
but if I restart my app I can loaded the various names , but if i create a new button , my array in the plist does not add the new name but initializes this and I get an error
how can I retrieve the array saved and accordingly add other names ?
Related
I need to display the content of a NSDictionary in a NSOutlineView.
I do this by using a struct that holds my data and which is used by my NSOutlineView as DataSource.
struct DataItem {
var caption : String
var text : String
}
dataInOutlineView: [DataItem]
I loop over all my items in my NSDictionary and add them to my data array
data.append(DataItem(caption: "KeyFromDict", text: "TextFromDict"))
And then I reload my NSOutlineView
outlineView.reloadData()
This concept works find but my problem is, that the data inside the NSDictionary changes regularly and I want to display the updated values in the NSOutlineView.
My first attempt was to remove all items from the array
data.removeAll
Then added the data again using the method above and then reload the NSOutlineView again but this results in a complete refresh of the NSOutlineView which means that all expanded items are collapsed again and the NSOutlineView is scrolled to top.
What would be a better idea to realize this? (if not is there a way to update the data using the method above but remain all expanded/collapsed and scroll location state?)
Thanks!
Im a beginner to developing apps and I'm trying to create my first real app using Xcode/Swift.
The problem I am having is setting up a table view to show certain information. I've managed to create other table views successfully but this one is slightly more complicated. I'll start off by breaking it down.
I have a variable that receives data via a segue called var recievedSelection = (choice: "", choiceValue:0.0) 'choice' being the name of selection and 'choiceValue' being the cost of that selection.
I then store this data into a dictionary array called var dict:[String:Double] = ["":0.0] by using this line of code:
self.dict[self.recievedSelection.choice] = self.recievedSelection.choiceValue
I have a table view all set up with delegate methods etc working and dequeueReusableCellWithIdentifier("basic", forIndexPath: indexPath). The numberOfSectionInTableView return 1 and numberOfRowsInSection return self.dict.count
What I am having problems with is using the data of each 'key' of self.dict to set as the cell.textLabel?.text and the data of each 'value' of self.dict to set as the cell.detailTextLabel?.text so that when the tableView loads the name and price of that selection is visible in each cell. Once user has made all their selections/choices as there will be a few to make throughout the app, there should be a list of those selections/choices that can be viewed in this table view.
Then there is a "Total" amount at the bottom just under the table view that calculates the overall amount.
I have also set up the table view to delete individual cells that when and if a cell is deleted that amount/price set into that cell is deducted from the total at the bottom of screen.
I am using NSUserDefaults to save the data loaded into the table view as there isn't any personal data being stored and it is only a brief estimate.
But the problem is, I can't get the table view to load both the values and keys of 'self.dict' into the table view textLabel and the detailTextLabel?
I hope that makes sense! I'd really appreciate any help.
I'm going to assume that you want to get values for your UITableViewDataSource from a Dictionary. An Array would be better, and you can likely change your code to use one for the UIViewController's data, but if you must, first get a set of the Dictionary's keys into an Array:
var myDataSource = Array(self.dict.keys)
Reassign this value EVERY TIME you edit/delete from the Dictionary, before you call tableView.reloadData(), to avoid index out of bounds crashes. Now, in your dataSource methods, you can check
self.dict[myDataSource[indexPath.row]]
and
myDataSource[indexPath.row]
and
return self.dict.count
This will give you both the size of the array that you need for number of rows, and the value and key you need from your Dictionary. If you like, you can also iterate over a Dictionary's keys and values with:
for (key, value) in self.dict {
//do something
}
I am not completely sure from your question what is causing the problem, meaning i'm not sure which value you are not getting. However, you can get those values by using:
let keyArray = dict.allKeys
then in your cellForIndexPath:
cell.textLabel.text? = keyArray[indexPath.row] //the "key"'s Value
cell.detailtextLabel.text? = dict[keyArray[indexPath.row]] // the "value"s value
Hope this helps your issue?
In Swift.
I want to store this two values the 1.Name and 2.Address these are two text field which are in single row of table view cell and i have “+” button where i can add multiple entires.
so here what ever the values i have enter in the textfield it has to store locally.
And then the next time when i comes to screen i have to retrieve the data and load into the tableview.
So tried with creating the Array of dictionary with having the key value pair of name and address.
Storage Class:
class StorageModel: NSObject
var dict = [String: String]
*) Main Class:
With having the table view delegate and other stuff.
*) TableView Cell:
Which contains the
Name text field
Address text field.
So how can i implement this functionality. I was stuck on this. Please help me friends. Thanks in Advance.
I want to get some values to the picker dynamically. Statically it is performing well. But when I want to add picker row dynamically from calling web service, there is an occurrence of NSRangeException. Whether the array having data and I am able to alert that data. I am using Titanium SDK for this iphone application.
if(gameTypeName.length>0){
alert(gameType.length);
picker.add(gameTypeName);
}
The array is creating as:
var typeName = college[j].GameTypeName;
gameTypeName.push(Titanium.UI.createPickerRow({title:typeName}));
Whether it is working fine with static data as:
var picker_data = [
Titanium.UI.createPickerRow({title:'Title 1',value:'1'}),
Titanium.UI.createPickerRow({title:'Title 2',value:'2'})
];
picker.add(picker_data);
Believe it or not, the Picker doesn't have a "Value" property.
You can use pickerView. But, easy to use Table View. you set array data in you TableView (tableView.data =;).
and for get value
tableView.addEventListener('click',function(e){
// own your requirement
Ti.API.log(e);
});
I think this is easy to use and good looking.
If, you want to show and hide. then you can use animation or window.modal property.
var win = Ti.UI.createWindow({});
win.add(tableview);
win.open({modal:true});
Hey guys, i have a simple app just a load of images in one image view. Each is just included in a plist file and called when a cell is selected in popover window. All i want is a button with an action to get next item in plist and display in the image window. this sounds easy but i cant figure out the code to grab next item in plist? can anyone help cheers
I'm not sure what the structure of your property list is, but I'm just going to guess that it's just a property list with one string containing the image name per row. The easiest way to manage this is to just dump the plist file into an array like this:
// Load the data
NSString *pathToFile = [[NSBundle mainBundle] pathForResource:someArrayNameString ofType:#"plist"];
self.someArrayYouCreated = [NSArray arrayWithContentsOfFile:pathToFile];
then you can access the data in the array like this:
// load it into some string you created
nextImageNameString = [someArrayYouCreated objectAtIndex:nextImageNumberHere];
and then you can just use that string name as the next image to load. So basically,
Dump plist into an array
Use objectAtIndex to access the images (remember, arrays start at index 0)