I'm currently populating 100 images using the following code, but I'm sure there's a more economical way of doing it with an If statement:
mapblock01.image = [UIImage imageNamed:#"block.png"]; mapblock01.hidden = TRUE;
mapblock02.image = [UIImage imageNamed:#"block.png"]; mapblock02.hidden = TRUE;
mapblock03.image = [UIImage imageNamed:#"block.png"]; mapblock03.hidden = TRUE;
mapblock04.image = [UIImage imageNamed:#"block.png"]; mapblock04.hidden = TRUE;
mapblock05.image = [UIImage imageNamed:#"block.png"]; mapblock05.hidden = TRUE;
------>
mapblock99.image = [UIImage imageNamed:#"block.png"]; mapblock99.hidden = TRUE;
mapblock100.image = [UIImage imageNamed:#"block.png"]; mapblock100.hidden = TRUE;
Any ideas?
for it, you can give tag for each UIImageView as 1,2,3..100 and set image as below:
for (int i = 0 ; i < 100 ; i++) {
UIImageView *imageV = (UIImageView *)[self.view viewWithTag:i];
imageV.image = [UIImage imageNamed:#"block.png"];
imageV.hidden = TRUE;
}
}
Related
This is my first post.
if (condition) {
trace("called");
p[1].visible = false;
j[1].visible = false;
}
With the code above "called" was printed in console but the both objects (buttons) still visible. Then when I try to put the set visibility (p[1].visible = false; and j[1].visible = false;) out from condition, it's work well.
I wonder what the problem here and how can I do set visibility with some condition?
[EDIT]
This is my actual source code. The code snippet above just to simple my question.
import flash.events.MouseEvent;
import flash.ui.Mouse;
import flash.events.Event;
stop();
var isInit:Boolean;
var val:Array;
var p:Array;
if (!isInit)
{
isInit = initial();
}
function initial():Boolean
{
trace("init");
val = new Array();
val[1] = 0;
val[2] = 0;
val[3] = 0;
val[4] = 0;
val[5] = 0;
val[6] = 0;
pinit();
jinit();
ainit();
binit();
cinit();
dinit();
einit();
return true;
}
function pinit():void
{
p = new Array();
p[1] = p1;
p[2] = p2;
p[3] = p3;
}
// event listener works
p[1].addEventListener(MouseEvent.CLICK, function (event:MouseEvent):void {
p[1].visible = false;
});
p[2].addEventListener(MouseEvent.CLICK, function (event:MouseEvent):void {
p[2].visible = false;
});
if (isInit)
{
trace("set visibility"); // this is printed as well
var i:int;
for (i = 1; i <= 3; i++)
{
setVisibility(i, val[i]);
}
}
function setVisibility(num:int, val:int):void
{
if (val==0)
{
p[num].visible = true;
j[num].visible = true;
}
else if (val==1)
{
trace("one");
p[num].visible = false;
j[num].visible = false;
}
else if (val==2)
{
trace("two");
p[num].visible = false;
j[num].visible = false;
a[num].visible = false;
}
else if (val==3)
{
trace("three");
p[num].visible = false;
j[num].visible = false;
a[num].visible = false;
b[num].visible = false;
}
else if (val==4)
{
trace("four");
p[num].visible = false;
j[num].visible = false;
a[num].visible = false;
b[num].visible = false;
c[num].visible = false;
}
else if (val==5)
{
trace("five");
p[num].visible = false;
j[num].visible = false;
a[num].visible = false;
b[num].visible = false;
c[num].visible = false;
d[num].visible = false;
}
}
The ainit, binit, cinit, etc functions are in another layer (on same frame) because the objects are there. The "one", "two", "three", "four", or "five" is printed but the visibility not set correctly.
Just to make your code simpler and easier to read.
With your val array you can populate it like this
val = new Array (0,0,0,0,0,0,0);
Yes this has seven numbers as an array starts at 0. You don't have to reference it but I would populate it just to make it look nicer.
I also changed the if else bit at the end to this:
switch (val){
case 0:
p[num].visible = true;
j[num].visible = true;
break;
case 1:
trace("one");
p[num].visible = false;
j[num].visible = false;
break;
case 2:
trace("two");
p[num].visible = false;
j[num].visible = false;
a[num].visible = false;
break;
case 3:
trace("three");
p[num].visible = false;
j[num].visible = false;
a[num].visible = false;
b[num].visible = false;
break;
case 4:
trace("four");
p[num].visible = false;
j[num].visible = false;
a[num].visible = false;
b[num].visible = false;
c[num].visible = false;
break;
case 5:
trace("five");
p[num].visible = false;
j[num].visible = false;
a[num].visible = false;
b[num].visible = false;
c[num].visible = false;
d[num].visible = false;
break;
}
As to your actual problem I don't think you can change a button from an array as it would become a copy of the button not the button itself (Hope that makes sense). I would still have the arrays but instead of the button visibility I'd use Booleans. So that at the end you could put:
btnButton.visible = p1;
Hope that's all Okay and of some use.
I am using codeigniter.I want to use 3 database in my project.I set the database.php file us,
$active_group = 'default';
$active_record = TRUE;
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'marketer_fp';
$db['default']['password'] = 'xxxxx';
$db['default']['database'] = 'marketer_fpr';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
$db['wpdb']['hostname'] = "localhost";
$db['wpdb']['username'] = "marketer_fprr";
$db['wpdb']['password'] = "yyyy";
$db['wpdb']['database'] = "marketer_mark";
$db['wpdb']['dbdriver'] = "mysql";
$db['wpdb']['dbprefix'] = "";
$db['wpdb']['pconnect'] = FALSE;
$db['wpdb']['db_debug'] = TRUE;
$db['wpdb']['cache_on'] = FALSE;
$db['wpdb']['cachedir'] = "";
$db['wpdb']['char_set'] = "utf8";
$db['wpdb']['dbcollat'] = "utf8_general_ci";
$db['wpfashn']['hostname'] = "localhost";
$db['wpfashn']['username'] = "marketer_fprr";
$db['wpfashn']['password'] = "yyyy";
$db['wpfashn']['database'] = "marketer_fah";
$db['wpfashn']['dbdriver'] = "mysql";
$db['wpfashn']['dbprefix'] = "";
$db['wpfashn']['pconnect'] = FALSE;
$db['wpfashn']['db_debug'] = TRUE;
$db['wpfashn']['cache_on'] = FALSE;
$db['wpfashn']['cachedir'] = "";
$db['wpfashn']['char_set'] = "utf8";
$db['wpfashn']['dbcollat'] = "utf8_general_ci";
The second and third database have same username and password.
In the controller ,inside construct function these 3 database are called.
$this->db3 =$this->load->database('wpfashn', TRUE);
$this->db2 =$this->load->database('wpdb', TRUE);
$this->db =$this->load->database('default', TRUE);
Inside another function a query is written,which should be executed by using the database 3.
$check=$this->db3->query("select * from mm_use_dat where wp_user_id='2'");
print_r($check->result());
this query return an empty array even if value present in the database.What should be the problem?Please help me to find a solution!
I have an issue with a UITableViewController where as soon as you scroll down the background image of the cell increases in size. All the images are set to a width of 320px but still after you scroll the cell background image expands.
Can anyone explain why this is happening and how to fix it?
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (jsonResults.count == 0)
{
return 1;
}
else
{
return [jsonResults count];
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UIImage *selectionBackground;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (jsonResults.count == 0)
{
cell.backgroundView = [[UIImageView alloc] initWithImage:[ [UIImage imageNamed:#"topAndBottomRow.png"]
stretchableImageWithLeftCapWidth:0.0 topCapHeight:5.0]];
selectionBackground = [UIImage imageNamed:#"topAndBottomRowSelected.png"];
[cell.selectedBackgroundView setBackgroundColor:[UIColor colorWithPatternImage:selectionBackground]];
cell.textLabel.text = #"Nothing was found :(";
cell.detailTextLabel.text = #"Click here to add a venue!";
//cell.textLabel.textColor= [UIColor colorWithRed:(79/255.0) green:(129/255.0) blue:(189/255.0) alpha:1] ;
cell.textLabel.font = [UIFont fontWithName:#"Berlin Sans FB" size:22];
cell.detailTextLabel.font = [UIFont fontWithName:#"Berlin Sans FB" size:14];
cell.backgroundColor = [UIColor clearColor];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
else
{
cell.selectionStyle = UITableViewCellSelectionStyleDefault;
cell.userInteractionEnabled = YES;
NSDictionary *venuesdict = [jsonResults objectAtIndex:indexPath.row];
NSString *addresslineone = [venuesdict objectForKey:#"address1"];
NSString *postcode = [venuesdict objectForKey:#"postcode"];
NSInteger sectionRows = [tableView numberOfRowsInSection:[indexPath section]];
NSInteger row = [indexPath row];
if (row == 0 && row == sectionRows - 1)
{
//rowBackground = [UIImage imageNamed:#"topAndBottomRow.png"];
cell.backgroundView = [[UIImageView alloc] initWithImage:[ [UIImage imageNamed:#"topAndBottomRow.png"]
stretchableImageWithLeftCapWidth:0.0 topCapHeight:5.0]];
selectionBackground = [UIImage imageNamed:#"topAndBottomRowSelected.png"];
}
else if (row == 0)
{
//rowBackground = [UIImage imageNamed:#"topRow.png"];
cell.backgroundView = [[UIImageView alloc] initWithImage:[ [UIImage imageNamed:#"topRow.png"]
stretchableImageWithLeftCapWidth:0.0 topCapHeight:5.0] ];
selectionBackground = [UIImage imageNamed:#"topRowSelected.png"];
}
else if (row == sectionRows - 1)
{
//rowBackground = [UIImage imageNamed:#"bottomRow.png"];
cell.backgroundView = [[UIImageView alloc] initWithImage:[ [UIImage imageNamed:#"bottomRow.png"]
stretchableImageWithLeftCapWidth:0.0 topCapHeight:5.0] ];
//rowBackground = [UIImage imageNamed:#"bottomRow.png"];
selectionBackground = [UIImage imageNamed:#"bottomRowSelected.png"];
}
else
{
cell.backgroundView = [[UIImageView alloc] initWithImage:[ [UIImage imageNamed:#"middleRow.png"]
stretchableImageWithLeftCapWidth:0.0 topCapHeight:5.0] ];
//rowBackground = [UIImage imageNamed:#"middleRow.png"];
selectionBackground = [UIImage imageNamed:#"middleRowSelected.png"];
}
UIImageView *imgView = [[UIImageView alloc] initWithFrame:cell.selectedBackgroundView.frame];
[imgView setImage:selectionBackground];
[cell.selectedBackgroundView addSubview:imgView];
[cell.selectedBackgroundView setBackgroundColor:[UIColor colorWithPatternImage:selectionBackground]];
cell.textLabel.text = [venuesdict objectForKey:#"name"];
NSString *imagename = [venuesdict objectForKey:#"imagename"];
cell.imageView.image = [UIImage imageNamed:imagename];
cell.detailTextLabel.text = [NSString stringWithFormat:#" %#, %#",addresslineone,postcode];
cell.textLabel.font = [UIFont fontWithName:#"Berlin Sans FB" size:22];
cell.detailTextLabel.font = [UIFont fontWithName:#"Berlin Sans FB" size:10];
cell.backgroundColor = [UIColor clearColor];
NSString *version = [[UIDevice currentDevice] systemVersion];
BOOL isAtLeast7 = [version floatValue] >= 7.0;
if (!isAtLeast7 == YES)
{
cell.detailTextLabel.backgroundColor = [UIColor grayColor];
cell.textLabel.backgroundColor = [UIColor grayColor];
}
}
return cell;
}
Try to change this line
UIImageView *imgView = [[UIImageView alloc] initWithFrame:cell.selectedBackgroundView.frame];
into this
UIImageView *imgView = [[UIImageView alloc] initWithFrame:cell.selectedBackgroundView.bounds];
I'm doing an application that requires core plot for drawing charts, I'm new to this library and I am finding it pretty hard to find good documentation or examples. I'm running into a problem where the line for the graph is not being display despite the fact that the data source method is getting called and returning the right number at the right index. Also the x Axis is being displayed wrong (Check the image below(1.0)). The Y axis is set correctly and the increment is also correct. I've been playing around trying to figure out what it's wrong but I spent too much time already so I was hoping to find some one here that could help or point me at the right direction. This is my implementation file :
-(void)initPlot {
[self generateData];
[self configureHost];
[self configureGraph];
[self configurePlots];
[self configureAxes];
}
- (void)generateData{
//Array containing all the dates that will be displayed on the X axis
dates = [NSArray arrayWithObjects:#"Apr 25", #"Apr 26", #"Apr 29",#"Apr 30", #"May 1", nil];
//Dictionary containing the name of the single set and its associated color
sets = [NSDictionary dictionaryWithObjectsAndKeys:[UIColor redColor], #"Plot 1",nil];
_dataY = [[NSMutableArray alloc] init];
[_dataY insertObject:[NSNumber numberWithFloat:618.0] atIndex:0];
[_dataY insertObject:[NSNumber numberWithFloat:613.0] atIndex:0];
[_dataY insertObject:[NSNumber numberWithFloat:613.0] atIndex:0];
[_dataY insertObject:[NSNumber numberWithFloat:614.0] atIndex:0];
[_dataY insertObject:[NSNumber numberWithFloat:604.0] atIndex:0];
_dataForPlot = [[NSMutableArray alloc] init];
for(int i = 0; i < dates.count; i++){
NSString *date = [dates objectAtIndex:i];
NSNumber *price = [_dataY objectAtIndex:i];
NSMutableDictionary *point1 = [[[NSMutableDictionary alloc] initWithObjectsAndKeys:date, #"x", price, #"y", nil] autorelease];
[_dataForPlot addObject:point1];
}
NSLog(#"Data %#",_dataForPlot);
}
-(void)configureHost {
_hostView.allowPinchScaling = NO;
}
-(void)configureGraph {
graph = [[CPTXYGraph alloc] initWithFrame:CGRectZero];
[graph applyTheme:[CPTTheme themeNamed:kCPTPlainBlackTheme]];
_hostView.hostedGraph = graph;
graph.plotAreaFrame.masksToBorder = NO;
// Configure the Graph Padding
graph.paddingLeft = 0.0f;
graph.paddingTop = 0.0f;
graph.paddingRight = 0.0f;
graph.paddingBottom = 0.0f;
CPTMutableLineStyle *borderLineStyle = [CPTMutableLineStyle lineStyle];
borderLineStyle.lineColor = [CPTColor whiteColor];
borderLineStyle.lineWidth = 2.0f;
graph.plotAreaFrame.borderLineStyle = borderLineStyle;
graph.plotAreaFrame.paddingTop = 10.0;
graph.plotAreaFrame.paddingRight = 10.0;
graph.plotAreaFrame.paddingBottom = 40.0;
graph.plotAreaFrame.paddingLeft = 70.0;
// Set graph title
graph.title = #"Test";
// Create and set text style
CPTMutableTextStyle *titleStyle = [CPTMutableTextStyle textStyle];
titleStyle.color = [CPTColor whiteColor];
titleStyle.fontName = #"Helvetica-Bold";
titleStyle.fontSize = 16.0f;
graph.titleTextStyle = titleStyle;
graph.titlePlotAreaFrameAnchor = CPTRectAnchorTop;
graph.titleDisplacement = CGPointMake(0.0f, 10.0f);
graph.plotAreaFrame.borderLineStyle = nil;
}
- (void)configurePlots{
CPTColor *aColor = [CPTColor redColor];
CPTMutableLineStyle *barLineStyle = [[[CPTMutableLineStyle alloc] init] autorelease];
barLineStyle.lineWidth = 1.0;
barLineStyle.lineColor = [CPTColor whiteColor];
CPTMutableTextStyle *whiteTextStyle = [CPTMutableTextStyle textStyle];
whiteTextStyle.color = [CPTColor whiteColor];
// Enable user interactions for plot space
CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *) graph.defaultPlotSpace;
plotSpace.allowsUserInteraction = YES;
plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0.0) length:CPTDecimalFromFloat(5.0)];
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat([self lowerValue]) length:CPTDecimalFromFloat([self higherValue])];
dataSourceLinePlot = [[[CPTScatterPlot alloc] init] autorelease];
dataSourceLinePlot.identifier = #"Plot 1";
dataSourceLinePlot.dataSource = self;
[graph addPlot:dataSourceLinePlot];
CPTGradient *areaGradient = [CPTGradient gradientWithBeginningColor :[CPTColor greenColor]
endingColor :[CPTColor blackColor]];
areaGradient.angle = -90.0f ;
CPTFill *areaGradientFill = [ CPTFill fillWithGradient :areaGradient];
dataSourceLinePlot.areaFill = areaGradientFill;
dataSourceLinePlot.areaBaseValue = CPTDecimalFromString (#"0.0");
dataSourceLinePlot.interpolation = CPTScatterPlotInterpolationLinear;
// Set up plot space
[plotSpace scaleToFitPlots:[NSArray arrayWithObjects:dataSourceLinePlot, nil]];
CPTMutablePlotRange *xRange = [plotSpace.xRange mutableCopy];
[xRange expandRangeByFactor:CPTDecimalFromCGFloat(1.1f)];
plotSpace.xRange = xRange;
CPTMutablePlotRange *yRange = [plotSpace.yRange mutableCopy];
[yRange expandRangeByFactor:CPTDecimalFromCGFloat(1.4f)];
plotSpace.yRange = yRange;
// Create styles and symbols
CPTMutableLineStyle *aLineStyle = [[dataSourceLinePlot.dataLineStyle mutableCopy] autorelease];
aLineStyle.lineWidth = 1.0;
aLineStyle.lineColor = aColor;
dataSourceLinePlot.dataLineStyle = aLineStyle;
//Add legend
CPTLegend *theLegend = [CPTLegend legendWithGraph:graph];
theLegend.numberOfRows = sets.count;
theLegend.fill = [CPTFill fillWithColor:[CPTColor colorWithGenericGray:0.15]];
theLegend.borderLineStyle = barLineStyle;
theLegend.cornerRadius = 10.0;
theLegend.swatchSize = CGSizeMake(15.0, 15.0);
whiteTextStyle.fontSize = 13.0;
theLegend.textStyle = whiteTextStyle;
theLegend.rowMargin = 5.0;
theLegend.paddingLeft = 10.0;
theLegend.paddingTop = 10.0;
theLegend.paddingRight = 10.0;
theLegend.paddingBottom = 10.0;
graph.legend = theLegend;
graph.legendAnchor = CPTRectAnchorTopLeft;
graph.legendDisplacement = CGPointMake(80.0, -10.0);
}
- (void)configureAxes{
CPTMutableTextStyle *axisTextStyle = [[CPTMutableTextStyle alloc] init];
axisTextStyle.color = [CPTColor whiteColor];
axisTextStyle.fontName = #"Helvetica-Bold";
axisTextStyle.fontSize = 11.0f;
// Grid line styles
CPTMutableLineStyle *majorGridLineStyle = [CPTMutableLineStyle lineStyle];
majorGridLineStyle.lineWidth = 0.75;
majorGridLineStyle.lineColor = [[CPTColor whiteColor] colorWithAlphaComponent:0.1];
CPTMutableLineStyle *minorGridLineStyle = [CPTMutableLineStyle lineStyle];
minorGridLineStyle.lineWidth = 0.25;
minorGridLineStyle.lineColor = [[CPTColor whiteColor] colorWithAlphaComponent:0.1];
// Line Style
CPTMutableLineStyle *lineStyle = [CPTMutableLineStyle lineStyle];
lineStyle.lineColor = [CPTColor whiteColor];
lineStyle.lineWidth = 2.0f;
CPTMutableLineStyle *axisLineStyle = [CPTMutableLineStyle lineStyle];
axisLineStyle.lineWidth = 2.0f;
axisLineStyle.lineColor = [CPTColor whiteColor];
//Axises
CPTXYAxisSet *axisSet = (CPTXYAxisSet *)graph.axisSet;
//Y axis
CPTXYAxis *y = axisSet.yAxis;
y.title = #"Price";
y.titleOffset = 50.0f;
y.labelingPolicy = CPTAxisLabelingPolicyAutomatic;
y.majorGridLineStyle = majorGridLineStyle;
y.minorGridLineStyle = minorGridLineStyle;
y.axisConstraints = [CPTConstraints constraintWithLowerOffset:0.0];
y. majorIntervalLength = CPTDecimalFromString(#"5");
y.minorTicksPerInterval = 4;
y.orthogonalCoordinateDecimal = CPTDecimalFromString(#"0");
y.minorTickLineStyle = nil;
y.labelOffset = 2.0f;
// Configure x-axis
CPTXYAxis *x = axisSet.xAxis;
x. majorIntervalLength = CPTDecimalFromString (#"5");
x.orthogonalCoordinateDecimal = CPTDecimalFromInt(0);
x.majorIntervalLength = CPTDecimalFromInt(5);
x.minorTicksPerInterval = 0;
x.labelingPolicy = CPTAxisLabelingPolicyNone;
x.majorGridLineStyle = majorGridLineStyle;
x.axisConstraints = [CPTConstraints constraintWithLowerOffset:0.0];
NSMutableArray *customLabels = [NSMutableArray arrayWithCapacity:[_dataForPlot count]];
static CPTMutableTextStyle *labelTextStyle = nil;
labelTextStyle = [[CPTMutableTextStyle alloc] init];
labelTextStyle.color = [CPTColor whiteColor];
labelTextStyle.fontSize = 10.0f;
int index = 0;
for(NSString *date in dates){
CPTAxisLabel *newLabel = [[CPTAxisLabel alloc] initWithText:date textStyle:labelTextStyle];
newLabel.tickLocation = CPTDecimalFromInt(index);
newLabel.offset = x.labelOffset + x.majorTickLength + 5;
newLabel.rotation = M_PI / 4;
[customLabels addObject:newLabel];
[newLabel release];
index++;
}
x.axisLabels = [NSSet setWithArray:customLabels];
}
- (float)higherValue{
NSNumber* max = [_dataY valueForKeyPath:#"#max.self"];
return [max floatValue];
}
- (float)lowerValue{
NSNumber* min = [_dataY valueForKeyPath:#"#min.self"];
return [min floatValue];
}
The Data Source Methods :
-(NSUInteger)numberOfRecordsForPlot:(CPTPlot *)plot {
return dates.count;
}
-(NSNumber *)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index {
NSString *key = (fieldEnum == CPTScatterPlotFieldX ? #"x" : #"y");
NSNumber *num = 0;
//if ( [(NSString *)plot.identifier isEqualToString:#"Plot 1"] ) {
num = [[_dataForPlot objectAtIndex:index] valueForKey:key];
if ( fieldEnum == CPTScatterPlotFieldX ) {
num = 0;
}
//}
CABasicAnimation *fadeInAnimation = [CABasicAnimation animationWithKeyPath:#"opacity"];
fadeInAnimation.duration = 1.0f;
fadeInAnimation.removedOnCompletion = NO;
fadeInAnimation.fillMode = kCAFillModeForwards;
fadeInAnimation.toValue = [NSNumber numberWithFloat:2.0];
[dataSourceLinePlot addAnimation:fadeInAnimation forKey:#"animateOpacity"];
NSLog(#"NUM : %# for key : %# at index : %i",num,key,index);
return num;
}
This is the image :
The x-axis is displayed exactly as you told it. It ranges between -0.25 and 5.25 (0 to 5 expanded by 10%) with five labels at 0, 1, 2, 3, and 4.
The datasource returns nil (0) for the CPTScatterPlotFieldX field for every point. This tells the plot to ignore that point. Based on the plot place range you've set up, you should return an NSNumber containing the index for that field.
I have a requirement to adding a path in my MKMapview between two annotation pin. There is no issue with ios 5 or older but when i try to run app in ios 6 app is surprisingly quit. below is my code. If there is any correction in my code then please suggest me.
1.So my question is suggest the best way how to decrees memory in my following code so that i can solve crash in my Application.
- (void)viewDidLoad
{
NVPolylineAnnotation *annotation = [[NVPolylineAnnotation alloc] initWithPoints:pathArray mapView:_mapView];
[_mapView addAnnotation:annotation];
[annotation release];
[pathArray removeAllObjects];
}
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
NSLog(#"%s",__FUNCTION__);
if ([annotation isKindOfClass:[NVPolylineAnnotation class]])
{
NSLog(#"=========ANOTATION=========NVPolylineAnnotationView START");
//ann=[ann initWithAnnotation:annotation mapView:_mapView];
NVPolylineAnnotationView *ann=[[NVPolylineAnnotationView alloc] init];
return [[ann initWithAnnotation:annotation mapView:_mapView] autorelease];//[[[NVPolylineAnnotationView alloc] initWithAnnotation:annotation mapView:_mapView] autorelease];
}
else if([annotation isKindOfClass:[MapViewAnnotation class]])
{
MKPinAnnotationView *annView=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:#"pointers"] ;
// annView.rightCalloutAccessoryView = [UIButton buttonWithType: UIButtonTypeDetailDisclosure];
annView.animatesDrop=NO;
annView.canShowCallout = TRUE;
return [annView autorelease];
}
else if([annotation isKindOfClass:[PlacePin class]])
{
{
MKPinAnnotationView *pinView = nil;
if(annotation != mapView.userLocation)
{
static NSString *defaultPinID = #"com.invasivecode.pin";
pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
if ( pinView == nil )
pinView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];
pinView.pinColor = MKPinAnnotationColorGreen;
pinView.canShowCallout = YES;
pinView.animatesDrop = NO;
}
else {
[mapView.userLocation setTitle:#"I am here"];
}
return pinView;
}
}
return nil;
}
- (void) mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views
{
NSLog(#"%s",__FUNCTION__);
// fixes that some marker are behind the polyline
for (int i=0; i<[views count]; i++)
{
MKAnnotationView *view = [views objectAtIndex:i];
if ([view isKindOfClass:[NVPolylineAnnotationView class]])
{
[[view superview] sendSubviewToBack:view];
/* In iOS version above 4.0 we need to update the polyline view after it
has been added to the mapview and it ready to be displayed. */
NSString *reqSysVer = #"4.0";
NSString *currSysVer = [[UIDevice currentDevice] systemVersion];
if ([currSysVer compare:reqSysVer options:NSNumericSearch] != NSOrderedAscending)
{
[self updatePolylineAnnotationView];
}
}
}
NSLog(#"----------didAddAnnotationViews");
}
- (void)updatePolylineAnnotationView
{
NSLog(#"%s",__FUNCTION__);
MKAnnotationView *annotationView = [views objectAtIndex:0];
id <MKAnnotation> mp = [annotationView annotation];
[mapView selectAnnotation:mp animated:NO];
*/
for (NSObject *a in [_mapView annotations])
{
if ([a isKindOfClass:[NVPolylineAnnotation class]])
{
NVPolylineAnnotation *polyline = (NVPolylineAnnotation *)a;
NSObject *pv = (NSObject *)[_mapView viewForAnnotation:polyline];
if ([pv isKindOfClass:[NVPolylineAnnotationView class]])
{
NVPolylineAnnotationView *polylineView =
(NVPolylineAnnotationView *)[_mapView viewForAnnotation:polyline];
[polylineView regionChanged];
}
}
}
}