I've got 5 labels and for each label im assigning a random value from an array when a button is clicked. Im wanting the first label to be changed then the second and then the third etc... but cannot seem to get it working. I've tried a loop and a timer to try and make the effect
You can try this, you have to create an array of labels or a collection of labels.
func assignLabel(){
if yourArray.count > labelsArrays.count {
yourArray.removeFirst()
}
for i in 0..<yourArray.count {
labelsArrays[i].text = yourArray[i]
}
}
Related
Hi guys. I have a tableView , which has one checkbox and one label in all rows.
So I tagged the checkboxes with labels. The goal is to make a set with clicked checkboxes. But the problem is I've done the checking and adding in set part. But I couldn't do unselecting part. --> I mean if I click the checkbox two times basically I deselect it so I have to remove the item from set, But I could't solve it.
If you can suggest something I ll be appreciated. Thanks.
func yourCheckBoxClicked(cbx:UIButton){
choosenSet.insert(self.tableData[cbx.tag])// this is the checkbox label which was clicked
print(choosenSet)
}
This is how you can achieve what you want:
func yourCheckBoxClicked(cbx:UIButton) {
let picked = tableData[cbx.tag]
if choosenSet.contains(picked) {
choosenSet.remove(picked) // uncheck
} else {
choosenSet.insert(picked) // check
}
}
I just started using AmCharts and have setup two line plots, one on top of the other, with their respective scrollbars.
Now, I want to "link" the scrollbars of both plots, so that if I move the scrollbar on the chart1, I'll get the same date range on the chart2. I imagine this shouldn't be too difficult with a listener, a get value function and a set value function, but I'm unable to find how to get the start/end values of the scrollbar so that I can play with them.
Any help would be appreciated.
thanks
There is a demo for this in the AmCharts Knowledge Base
https://www.amcharts.com/kbase/share-scrollbar-across-several-charts/
This is the code that is syncing the scrollbars, (I have added the annotations):
Create an array to populate with your charts
var charts = [];
Create how ever many charts you need
charts.push(AmCharts.makeChart("chartdiv", chartConfig));
charts.push(AmCharts.makeChart("chartdiv2", chartConfig2));
charts.push(AmCharts.makeChart("chartdiv3", chartConfig3));
Iterate over the charts, adding an event listener for "zoomed" which will share the event handler
for (var x in charts) {
charts[x].addListener("zoomed", syncZoom);
}
The event handler
function syncZoom(event) {
for (x in charts) {
if (charts[x].ignoreZoom) {
charts[x].ignoreZoom = false;
}
if (event.chart != charts[x]) {
charts[x].ignoreZoom = true;
charts[x].zoomToDates(event.startDate, event.endDate);
}
}
}
I have two line series and how do I make points on both series selected at the same time? Basically, my chart has 2 y values sharing the same x value and I'm representing them as two series. I want to display both points as selected for a given X Value.
Hi there,Thanks for the reply. I'm doing that in
- (void)sChart:(ShinobiChart *)chart toggledSelectionForPoint:(SChartDataPoint *)dataPoint inSeries:(SChartSeries *)series atPixelCoordinate:(CGPoint)pixelPoint
SChartDataPoint* point1Series1 = [chart.datasource sChart:chart dataPointAtIndex:dataPoint.index forSeriesAtIndex:0];
point1Series1.selected = YES;
SChartDataPoint* point1Series2 = [chart.datasource sChart:chart dataPointAtIndex:dataPoint.index forSeriesAtIndex:1];
point1Series2.selected = YES;
When I print the selected state of both points after this line of code, they return 1(selected) but they don't seem to appear as selected on the chart only the one I selected on the chart on device seem to appear as selected though I'm calling redrawChart after that. Any help would be appreciated
I think that it's likely (and I'm guessing because I can't see your code) that your chart data source isn't returning a reference to a datapoint which is part of the chart, but instead generating a new datapoint object each time you request one.
In order to cope with this you can request the data points from the chart itself, via the dataSeries property on SChartSeries objects.
The following delegate method should perform the selection you require.
- (void)sChart:(ShinobiChart *)chart toggledSelectionForPoint:(SChartDataPoint *)dataPoint inSeries:(SChartSeries *)series atPixelCoordinate:(CGPoint)pixelPoint
{
// Selection details
NSInteger dataPointIndex = dataPoint.index;
BOOL selected = dataPoint.selected;
for (SChartSeries *chartSeries in chart.series) {
// If only one data point in the series can be selected at once, then deselect the rest
if(!series.togglePointSelection && selected) {
for(SChartDataPoint *dp in chartSeries.dataSeries.dataPoints) {
dp.selected = NO;
}
}
// Find the data point and perform the selection
SChartDataPoint *dp = chartSeries.dataSeries.dataPoints[dataPointIndex];
dp.selected = selected;
}
}
Hope that helps.
You should be able to set .selected on the datapoints and customise the series.style.selectedPointStyle properties to display points how you wish :)
Few days back this question was about changing the label text from an other class. I changed a few things around:
I now have a function setLabelText:
- (void)setLabelText:(NSString*)text{
//myLabel.text = text;
[myLabel performSelectorOnMainThread : # selector(setText : ) withObject:text waitUntilDone:YES];
NSLog(#"class:%#, label:%#", self, myLabel);
}
Both self and label are filled, but the display is not showing the correct text..
I'm calling this function from an other class, if I change my label text from a button on the viewcontroller it changes correctly.
EDIT:
I have the label changing now, every time when the class is done with it's functions the label edits the text. Although.. this is always the last set value, I need it to change every time it gets into a for loop, how can I get this to work? Seems it doesn't update the viewController while the app is doing it's for loop
I am trying my first iphone app. I am stuck now. I have two label that display seperate random numbers. I used a button and IBAction to generate the numbers then pass them to the label. Now I need to determine when the two numbers match and then print "match" in another label. I am trying all kinds of different things but somehow I am missing something. If anyone can help explain how to do this form a code point of view and hooking it into interface builder that would be awesome! Thanks
In the method where you get and show the random numbers you simply compare them and change the text in the third label accordingly.
- (IBAction)buttonPressed {
// Generate the 2 random numbers and show them in the labels here.
// Then compare them and show the result in the third label:
if (randomNumber1 == randomNumber2) {
thirdLabel.text = #"Match";
} else {
thirdLabel.text = #"No Match";
}
}