I have to find my location on image .
http://www.mallorcaresidencia.com/layout/map_230_0.png
touch on North area , tap on center,tap on south etc. find location particular area then event generate.
if (((touchLocation.x <219 && touchLocation.y>19) && (touchLocation.x <221 && touchLocation.y<97)) || ((touchLocation.x <143 && touchLocation.y<78) && (touchLocation.x >129 && touchLocation.y<58))) {
cellimgmap.image = [UIImage imageNamed:#"map_north.png"];
}else if (((touchLocation.x >218 && touchLocation.y<94) && (touchLocation.x <270 && touchLocation.y>165)) || ((touchLocation.x <298 && touchLocation.y>111) && (touchLocation.x >257 && touchLocation.y>84))) {
cellimgmap.image = [UIImage imageNamed:#"map_northeast.png"];
}else if (((touchLocation.x >131 && touchLocation.y>55) && (touchLocation.x <135 && touchLocation.y<111)) || (touchLocation.x <102 && touchLocation.y<135) || ((touchLocation.x <69 && touchLocation.y<150) && (touchLocation.x >42 && touchLocation.y<133))) {
cellimgmap.image = [UIImage imageNamed:#"map_westnorthwest.png"];
}
Related
In viewDidLoad I'm programmatically creating 13 blocks using the code:
for (int X = 1; X <= 13; X++) {
UIImageView *iceBlockX = [[UIImageView alloc] initWithFrame:CGRectMake((28 * X - 4),52,28,28)];
iceBlockX.image = [UIImage imageNamed:#"iceBlock.png"];
iceBlockX.tag = X;
[self.view insertSubview:iceBlockX belowSubview:_topPenguinCollisionTarget];
}
I need to detect a collision between an imageView created on the storyboard (penguin) and any one programmatically-created imageView block. If this is possible, what is the code used for the detection? I've tried the following code, but it's not working:
if (((CGRectIntersectsRect(_penguin.frame, _iceBlock1.frame)) && (_iceBlock1.hidden == NO)) ||
((CGRectIntersectsRect(_penguin.frame, _iceBlock2.frame)) &&(_iceBlock2.hidden == NO)) ||
((CGRectIntersectsRect(_penguin.frame, _iceBlock3.frame)) && (_iceBlock3.hidden == NO)) ||
((CGRectIntersectsRect(_penguin.frame, _iceBlock4.frame)) && (_iceBlock4.hidden == NO)) ||
((CGRectIntersectsRect(_penguin.frame, _iceBlock5.frame)) &&(_iceBlock5.hidden == NO)) ||
((CGRectIntersectsRect(_penguin.frame, _iceBlock6.frame)) && (_iceBlock6.hidden == NO)) ||
((CGRectIntersectsRect(_penguin.frame, _iceBlock7.frame)) && (_iceBlock7.hidden == NO)) ||
((CGRectIntersectsRect(_penguin.frame, _iceBlock8.frame)) && (_iceBlock8.hidden == NO)) ||
((CGRectIntersectsRect(_penguin.frame, _iceBlock9.frame)) && (_iceBlock9.hidden == NO)) ||
((CGRectIntersectsRect(_penguin.frame, _iceBlock10.frame)) && (_iceBlock10.hidden == NO)) ||
((CGRectIntersectsRect(_penguin.frame, _iceBlock11.frame)) && (_iceBlock11.hidden == NO)) ||
((CGRectIntersectsRect(_penguin.frame, _iceBlock12.frame)) && (_iceBlock12.hidden == NO)) ||
((CGRectIntersectsRect(_penguin.frame, _iceBlock13.frame)) &&(_iceBlock13.hidden == NO)))
{
NSLog(#"A collision was detected");
}
CGRectIntersectsRect return true if "rect1" intersects "rect2", else false.
- (BOOL)didUIImageCollided{
for (int X = 1; X <= 13; X++)
{
UIImageView *iceBlockX = (UIImageView*)[self.view viewWithTag:X];
if(CGRectIntersectsRect(_penguin.frame, iceBlockX.frame))
{
return YES;
}
}
return NO;
}
I have a table with 30 different columns and I am trying to write a method that calls on each column containing a value.
eg.
def add_details
customer = Customer.find self.customer_id
if self.room1.present? && self.room2.present? && self.room3.present? && self.room4.present? && self.room5.present? && self.room6.present? && self.room7.present? && self.room8.present? && self.room9.present? && self.room10.present? && self.room11.present? && self.room12.present? && self.room13.present? && self.room14.present? && self.room15.present? && self.room16.present? && self.room17.present? && self.room18.present? && self.room19.present? && self.room20.present? && self.room21.present? && self.room22.present? && self.room23.present? && self.room24.present? && self.room25.present? && self.room26.present? && self.room27.present? && self.room28.present? && self.room29.present? && self.room30.present?
elsif self.room.present? && self.room2.present? && self.room3.present? && self.room4.present? && self.room5.present? && self.room6.present? && self.room7.present? && self.room8.present? && self.room9.present? && self.room10.present? && self.room11.present? && self.room12.present? && self.room13.present? && self.room14.present? && self.room15.present? && self.room16.present? && self.room17.present? && self.room18.present? && self.room19.present? && self.room20.present? && self.room21.present? && self.room22.present? && self.room23.present? && self.room24.present? && self.room25.present? && self.room26.present? && self.room27.present? && self.room28.present? && self.room29.present?
room = Room.find self.room
.....
room29 = ... end end
This is a whole lot of repeating myself and I know ruby is dynamic so there should be a way to increment the numbers with like a for loop and it would still work. I dont know if anyone has a better way to write this
Well you can do something like this:
if (up_to_29 = (1..29).all?{|i| send("column#{i}").present? }) && column30.present?
# update_columns column1: ...
elsif up_to_29
# update_columns column1: ...
Options 1: Assume that all model attributes need to validate
validate_needed_columns = Model.attribute_names
while validate_needed_columns.present? do
if validate_needed_columns.all?{ |c| Model[c].present? }
Model.update_columns(<Hash here>)
break
end
validate_needed_columns.pop
end
Options 2: Use mapping to set which columns need to update
validate_needed_columns = {
column_name_1: value_to_update_1,
...
column_name_n: value_to_update_n
}
validate_needed_column_keys = validate_needed_columns.keys
while validate_needed_column_keys.present? do
if validate_needed_column_keys.all?{ |c| Model[c].present? }
Model.update_columns(<Use mapping to set value here>)
break
end
validate_needed_column_keys.pop
end
You can use a range of numbers to loop through and call "column_#{i}" on each one. The all? method will return true if every iteration of the loop is true. Try something like this:
if (1..30).all?{|index| self.send("column#{index}")&.present? }
#...
elsif (1..29).all?{|index| self.send("column#{index}")&.present? }
#...
I have a uitextfield and i have got a search option using this uitextfield.When i enter the text it works well but when i clear the text i get "object returned empty description check" when i print it using po command in console. For checking this i have used the following code:
if(_nameTextField.text !=nil || _nameTextField.text.length !=0 || ![_nameTextField.text isEqual:#""]|| _nameTextField.text != NULL || ![_nameTextField.text isEqualToString:#""]){
}
But still it enters into the loop
use && instead of ||
if(_nameTextField.text !=nil && _nameTextField.text.length !=0 && ![_nameTextField.text isEqual:#""]&& _nameTextField.text != NULL && ![_nameTextField.text isEqualToString:#""]){
}
Please use this..it help you:
if (_nameTextField.text && _nameTextField.text.length!=0)
{
}
Use like this, it will work
if(_nameTextField.text !=nil && _nameTextField.text.length > 0 ){
//...
}
I have list of days (from monday till sunday).
When a user selects monday till friday or saturday and sunday I want my app to show it's hyponym (weekdays/weekends).
Does iOS provide some default functionality for this (If i'm not mistaken the iOS Alarm app does the same) or do I have to write this functionality myself?
Provided that you have a NSArray with the selected days as numbers, named selectedDays, and that 0 and 6 are weekend days:
NSString *name = nil; // Fill this with the default values (concatenate all names of selected days)
bool days[] = {0,0,0,0,0,0,0};
for (NSNumber *day in selectedDays)
{
int d = [day intValue];
if (d >= 0 && d <= 6) days[d] = true;
}
if ( days[0] == true
&& days[1] == false
&& days[2] == false
&& days[3] == false
&& days[4] == false
&& days[5] == false
&& days[6] == true)
{
name = #"Weekend";
}
if ( days[0] == false
&& days[1] == true
&& days[2] == true
&& days[3] == true
&& days[4] == true
&& days[5] == true
&& days[6] == false)
{
name = #"Weekdays";
}
var postsidebar = from post in postrepository.GetAllPosts()
join pstmt in postrepository.GetAllPostMetas()
on post.int_PostId equals pstmt.int_PostId
where (post.int_PostTypeId == 4
&& post.int_PostStatusId == 2
&& post.int_OrganizationId == layoutrep.GetSidebarDetailById(SidebarDetailsId).int_OrganizationId)
&& (pstmt.vcr_MetaKey.Contains(filter) && pstmt.vcr_MetaValue.Contains("true")
&& (System.DateTime.Now >=
Convert.ToDateTime(pstmt.Post.PostMetas.FirstOrDefault(m =>
m.vcr_MetaKey == "Publish Date").vcr_MetaValue)))
select post;
how can i check for empty in this part in Date(it is giving error)
&& (System.DateTime.Now >= Convert.ToDateTime(pstmt.Post.PostMetas.FirstOrDefault(m =>
m.vcr_MetaKey == "Publish Date").vcr_MetaValue)))
You could try eliminated the possibility of an empty value first and then try your cast afterward.
&& pstmt.Post.PostMetas.FirstOrDefault(m =>
m.vcr_MetaKey == "Publish Date"
&& !string.IsNullOrEmpty(m.vcr_MetaValue))
&& (System.DateTime.Now >=
Convert.ToDateTime(pstmt.Post.PostMetas.FirstOrDefault(m =>
m.vcr_MetaKey == "Publish Date").vcr_MetaValue)))
Try this:
// declare the action for re-use
Func<PostMeta,bool> action = m => m.vcr_MetaKey == "Publish Date";
// then test for Any() before comparing anything
&& (pstmt.Post.PostMetas.Any(action) && System.DateTime.Now >= Convert.ToDateTime(pstmt.Post.PostMetas.First(action).vcr_MetaValue)))