I was trying to clean up deprecation warnings of a certain project and the snippet of code looked like:
NSInputManager* im = [NSInputManager currentInputManager];
if (im && [im markedRange].length > 0) return NO;
I got this far:
NSTextInputContext* im = [NSTextInputContext currentInputContext];
if (im && [im /* What goes here? */].length > 0) return NO;
I am trying to get the marked range of the NSTextInputContext. How would I go about doing that?
This should work:
NSTextInputContext* context = [NSTextInputContext currentInputContext];
id<NSTextInputClient> client = context.client;
if (client && client.markedRange.length > 0) return NO;
The client is usually the text view with the focus, so the first responder of the key window. So, you can maybe bypass looking it up this way and just go straight to the text view.
Related
Hello I am having the above error in production but all works well in development. I am using the code bellow to get the path to the main image for the property but it defaults into the else despite the if not being false plus the else does not find the paths even when dump shows that the object has been returned
//check if there are hotels in the selected destination
if($hotels->isNotEmpty()){
//Loop through the hotels
foreach($hotels as $hotel){
//get hotels main image
$banner = Photo::where(['p_id'=>$hotel->id])->where(['is_main'=>1])->first();
$altbanner = Photo::where(['p_id'=>$hotel->id])->first();
$banner_path = "";
$altText = "";
if($banner!=null){
$banner_path = $banner->path;
$altText = $banner->alt_text;
}else{
$banner_path = $altbanner->path;
$altText = $altbanner->alt_text;
}
Have you checked your database if each hotel has an image? Based on your question and explanation, there is a part of the for each that returns null for the image hence the if part fails and the else return the error. If that is the case then you may want to check and sort it by uploading the image or modifying your checks to handle cases where no image is found.
I think the way you are using the where clause isn't right
foreach($hotels as $hotel){
//get hotels main image
$banner = Photo::where('p_id',$hotel->id)->where('is_main',1)->first();
$altbanner = Photo::where('p_id',$hotel->id)->first();
// .....
if($banner){
$banner_path = $banner->path;
// ......
Could you help me find the error in my code.
import javax.swing.JOptionPane;
String mortgagetype;
mortgagetype = JOptionPane.showInputDialog("What type of mortgage do you desire? (open or closed, only)");
if (mortgagetype == "open" || mortgagetype == "closed") {
print("hello");
}
I want the program to print hello if the user inputs open or closed. However it doesn't and I don't know what the problem is.
Instead of using mortgagetype == "something" in the if statement, use mortgagetype.equals("something").
I have a menu displaying files that are stored in a Core Data model. I'm able to add a new object to the model and display it on the menu. Now, I would like to delete one file from the menu when right clicking on it and choose delete, everything I tried didn't work so far:
- (IBAction)RemoveSelectedFile:(id)sender {
if ([((NSMenuItem *)sender).menu isEqual:self.fileRecordContextMenu]) {
// get the indices that have been clicked on
NSIndexSet * indices = [self _indexesToProcessForContextMenuForTable:self.fileRecordsTable];
ClassFileRecord * fileRecord = (self.document && self.document.fileRecordsController && self.document.fileRecordsController.arrangedObjects && indices && indices.count > 0) ? [self.document.fileRecordsController.arrangedObjects objectAtIndex:indices.firstIndex] : nil;
if (fileRecord) {
// Path to the file
NSString * u = fileRecord.sourceFilePath;
if (u) {
// Delete Object
}
}
}
}
UPDATE:
I found an easy solution using the NSArrayController:
NSArray * selectedObjects = self.fileRecordsController.selectedObjects;
[self.fileRecordsController removeObjects:selectedObjects];
I had defined an imageview in my layout for the individual items of a list, and they were set invisible. When I clicked a button, they will be show,but I can't get this action act. I want to achieve this effect. Here is my code:
//file:list_view_test.jade
Alloy
Window#win
Button#btn(title = "Show" onClick = "show_the_image_view")
ListView#list_view(defaultItemTemplate = "list_style")
Templates
ItemTemplate(name = "list_style")
View#item_view(bindId = "bind_item_view")
ImageView#image_view(bindId = "bind_image_view")
ListSection
ListItem(bind_item_view:backgroundImage = "/images/backgroundImage_1.png"
bind_image_view:image = "/images/unchecked_image.png")
ListItem(bind_item_view:backgroundImage = "/images/backgroundImage_2.png"
bind_image_view:image = "/images/unchecked_image.png")
//file:list_view_test.stss
#item_view{
width:100%;
height:10%
}
#image_view{
top:0;
left:0;
width:20%;
height:20%;
visible:false
}
//file:list_view_test.coffee
show_the_image_view = ->
if "Show" == $.btn.getTitle()
$.btn.setTitle("Hide")
//$.image_view.setVisible(true) (this code had been commented, cause it's wrong)
else if "Hide" == $.btn.getTitle()
$.btn.setTitle("Show")
//$.image_view.setVisible(false) (this code had been commented, cause it's wrong)
$.list_view.addEventListener('itemclick', = (e) ->
if e.itemIndex == 0
//$.image_view.setImage('/images/checked_image.png') (this code had been commented, cause it's wrong)
else if e.itemIndex == 1
//$.image_view.setImage('/images/checked_image.png') (this code had been commented, cause it's wrong)
Is there anyone who has a good method to solve the problem?
I am making an iPhone app with cocos2d and Everytime I try to return a variable from a function I get a run time error on the code below...
GB2ShapeCache *cache = [GB2ShapeCache sharedShapeCache];
//EXC_BAD_ACCESS run time error here
*eggFixture = [cache addFixturesToBody:body forShapeName:#"egg3"];
I don't know what I am doing wrong... here is the code for addFixturesToBody...
-(b2Fixture) addFixturesToBody:(b2Body*)body forShapeName:(NSString*)shape
{
BodyDef *so = [shapeObjects objectForKey:shape];
assert(so);
b2Fixture *Fixi;
FixtureDef *fix = so->fixtures;
while(fix)
{
Fixi = body->CreateFixture(&fix->fixture);
fix = fix->next;
}
return *Fixi;
}
and here I define my variable eggFixture
b2Fixture *eggFixture;
and here is where I try to use the b2fixture eggFixture later
for(pos = _contactListener->_contacts.begin();
pos != _contactListener->_contacts.end(); ++pos) {
MyContact contact = *pos;
if ((contact.fixtureA == locations.platformFixture && contact.fixtureB == eggFixture) ||
(contact.fixtureA == eggFixture && contact.fixtureB == locations.platformFixture)) {
NSLog(#"Ball hit bottom!");
}
}
Any help? thankyou :)
Looks like body is nil. It will certainly crash here when body is nil:
Fixi = body->CreateFixture(&fix->fixture);
This article has some tips for debugging issues like EXC_BAD_ACCESS.