Konva Textpath: how does it calculate x and y position - html5-canvas

EDIT: there was a bug in the code, so this question is not valid.
I'm trying hard to get Konva.textpath to work. The problem is that the x & y point seems completely random.
There are 3 examples. The green box is placed on the same x/y as the textpath, the red line is the path and all paths (in data) starts at 0,0.
Example 1:
Path: M0,0c138.1,0,250,111.9,250,250S138.1,500,0,500s-250-111.9-250-250S-138.1,0,0,0
Example 2:
Same path, but with text overflowing. It's not easy to see, but the start of the path is moved about 18px
Example 3:
Path M0,0c138.1,0,250,111.9,250,250S138.1,500,0,500s-250-111.9-250-250S-138.1,0,0,0
I fail to see any logic to the placement. The expected result would be that x & y of the text should be the start of the text.
These are not some hard to find examples. Every path I try behaves the same.
Thankful for an explanation.

If I understand your question, you are saying that the if you set the co-ords of the small green rectangle to the same (x,y) as the first point in the path then the position does not match the start of the path.
Here is a snippet of code with which I am trying to confirm your result but for me the pink rectangle is placed where it should be.
What other code do you have? Maybe an offset is being applied, or maybe a group ? It seems unlikely that your path starts at stage(0,0) because that would see some clipping of the letter 'L' which would draw partially off the stage.
Conclusion: more info required to repro the issue, or double check your code?
// Set up the canvas / stage
var stage = new Konva.Stage({container: 'container1', width: 600, height: 300});
// Add a layer for line
var layer = new Konva.Layer({draggable: false});
stage.add(layer);
// draw a path.
var path = new Konva.Path({
x: 0,
y: 0,
stroke: 'cyan'
});
layer.add(path)
var dot = new Konva.Rect({x: 0, y: 0, width: 20, height: 20, fill: 'magenta' });
layer.add(dot);
var path = new Konva.Path({
x: 0,
y: 0,
stroke: 'cyan'
})
layer.add(path);
var textpath = new Konva.TextPath({
x: 0,
y: 0,
fill: '#333',
fontSize: 32,
fontFamily: 'Arial',
text: 'Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum'
});
layer.add(textpath);
stage.draw()
$('#path1').on('click', function(){
var data = "M20,20c138.1,0,250,111.9,250,250S138.1,500,0,500s-250-111.9-250-250S-138.1,0,0,0";
textpath.setData(data);
path.setData(data);
var pt = path.getPointAtLength(0);
dot.position({x: pt.x, y: pt.y});
layer.draw();
})
$('#path2').on('click', function(){
var data = "M 120 20 a 100 100 0 1 0 0.00001 0";
textpath.setData(data);
path.setData(data);
var pt = path.getPointAtLength(0);
dot.position({x: pt.x, y: pt.y});
layer.draw();
})
$('#path3').on('click', function(){
var data = "M200 200 S 200.5 200 201.1 200.2 201.5 200.4 202 200.7 202.4 201.1 202.8 201.5 203.1 202.1 203.3 202.7 203.5 203.3 203.6 204 203.5 204.7 203.4 205.4 203.2 206.1 202.9 206.9 202.5 207.6 201.9 208.3 201.3 209 200.6 209.6 199.8 210.1 198.9 210.6 197.9 211 196.8 211.3 195.7 211.5 194.6 211.6 193.3 211.5 192.1 211.4 190.8 211.1 189.6 210.7 188.3 210.1 187.1 209.4 185.9 208.6 184.7 207.6 183.6 206.5 182.6 205.2 181.7 203.9 181 202.4 180.3 200.8 179.8 199.2 179.4 197.4 179.1 195.6 179.1 193.7 179.2 191.8 179.5 189.8 179.9 187.8 180.6 185.9 181.4 184 182.5 182.1 183.7 180.3 185.1 178.5 186.7 176.9 188.4 175.4 190.3 174 192.4 172.8 194.6 171.7 196.9 170.8 199.4 170.1 201.9 169.7 204.5 169.4 207.2 169.4 209.9 169.6 212.6 170 215.3 170.7 218 171.6 220.6 172.8 223.2 174.2 225.7 175.9 228 177.8 230.2 179.9 232.2 182.3 234.1 184.8 235.8 187.5 237.2 190.5 238.4 193.5 239.3 196.7 240 200 240.4 203.4 240.5 206.8 240.3 210.3 239.8 213.9 239 217.4 237.9 220.8 236.4 224.2 234.7 227.5 232.7 230.7 230.3 233.7 227.7 236.5 224.9 239.2 221.7 241.6 218.4 243.8 214.8 245.7 211.1 247.3 207.2 248.5 203.1 249.5 199 250.1 194.7 250.4 190.4 250.3 186.1 249.8 181.8 249 177.5 247.8 173.3 246.2 169.3 244.2 165.3 241.9 161.6 239.2 158 236.2 154.7 232.9 151.6 229.3 148.9 225.4 146.4 221.2 144.3 216.8 142.6 212.2 141.3 207.4 140.3 202.5 139.8 197.5 139.7 192.4 140 187.2 140.8 182.1 142 177 143.6 172 145.7 167.1 148.2 162.4 151.1 157.8 154.5 153.5 158.2 149.5 162.3 145.7 166.7 142.3 171.4 139.2 176.4 136.5 181.6 134.2 187.1 132.4 192.8 131 198.5 130.1 204.4 129.7 210.4 129.8 216.3 130.4 222.2 131.5 228.1 133.1 233.9 135.2 239.4 137.9 244.8 141 250 144.5 254.8 148.5 259.4 153 263.5 157.8 267.3 163 270.6 168.5 273.5 174.4 275.9 180.5 277.8 186.8 279.2 193.4 280 200 280.3 206.7 279.9 213.5 279 220.3 277.6 227 275.5 233.6 272.9 240.1 269.7 246.3 266 252.3 261.8 258 257.1 263.4 251.9 268.4 246.3 272.9 240.3 277 233.9 280.6 227.2 283.7 220.2 286.2 213 288.1 205.6 289.4 198.1 290.1 190.5 290.2 182.9 289.6 175.3 288.4 167.8 286.5 160.5 284 153.3 280.8 146.4 277.1 139.8 272.7 133.6 267.8 127.7 262.4 122.3 256.4 117.4 250 113.1 243.2 109.3 235.9 106.1 228.4 103.5 220.5 101.6 212.4 100.4 204.2 99.8 195.8 100 187.4 100.9 178.9 102.5 170.6 104.8 162.3 107.8 154.2 111.5 146.4 115.9 138.9 120.9 131.7 126.5 124.9 132.7 118.6 139.4 112.8 146.7 107.6 154.4 103 162.4 99 170.9 95.7 179.6 93.1 188.6 91.3 197.7 90.2 206.9 89.8 216.2 90.3 225.5 91.5 234.6 93.5 243.6 96.3 252.4 99.8 260.9 104.1 269 109.1 276.7 114.8 284 121.1 290.7 128.1 296.8 135.7 302.4 143.7 307.2 152.3 311.3 161.2 314.7 170.6 317.3 180.2 319 190 320 200 320.1 210.1 319.4 220.2 317.8 230.2 315.3 240.2 312.1 249.9 308 259.4 303.1 268.5 297.4 277.2 291 285.4 283.9 293.1 276.1 300.3 267.7 306.7 258.8 312.5 249.4 317.5 239.6 321.7 229.4 325.1 218.9 327.7 208.1 329.3 197.3 330.1 186.3 330 175.4 328.9 164.6 326.9 153.9 324 143.5 320.2 133.3 315.5 123.6 309.9 114.3 303.6 105.6 296.4 97.5 288.5 90 279.9 83.2 270.7 77.2 260.9 72.1 250.7 67.8 239.9 64.4 228.8 61.9 217.4 60.4 205.9 59.9 194.1 60.3 182.4 61.8 170.6 64.2 159 67.6 147.6 72 136.4 77.3 125.7 83.5 115.4 90.6 105.6 98.5 96.4 107.2 87.8 116.6 80 126.7 73 137.3 66.8 148.5 61.5 160.1 57.2 172.1 53.8 184.4 51.5 196.9 50.2 209.4 49.9 222 50.7 234.6 52.5 247 55.4 259.1 59.4 270.9 64.4 282.3 70.3 293.2 77.2 303.5 85.1 313.1 93.8 322 103.3 330.2 113.5 337.4 124.5 343.7 136 349.1 148.1 353.4 160.6 356.7 173.5 358.9 186.7 358.9 186.7";
textpath.setData(data);
path.setData(data);
var pt = path.getPointAtLength(0);
dot.position({x: pt.x, y: pt.y});
layer.draw();
})
$('#path1').trigger('click');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/konva/2.5.1/konva.min.js"></script>
<div >
<button id='path1'>Path 1</button>
<button id='path2'>Path 2</button>
<button id='path3'>Path 3</button>
</div>
<div id='container1' style="width: 300px, height: 200px; background-color: silver; margin:10px;padding:10px;"></div>
<div id='img'></div>

Related

Playwright: Click function not happening on visible element

I am trying to click on a link. I have verified the xpath for that element using SelectorsHub and Chropath as well, so there is no issue with the locator. I have tried 3-4 xpaths but I keep on getting the same error. Please see below the error which I am getting in console:-
locator.click: Target closed
=========================== logs ===========================
waiting for selector "//span[contains(text(),'Received Date')]/following-sibling::span/span/span[#aria-label='caret-up']"
selector resolved to visible <span role="img" aria-label="caret-up" class="anticon …>…
attempting click action
waiting for element to be visible, enabled and stable
element is visible, enabled and stable
scrolling into view if needed
done scrolling
checking that element receives pointer events at (485.95,278.14)
… intercepts pointer events
retrying click action, attempt #1
waiting for element to be visible, enabled and stable
element is visible, enabled and stable
scrolling into view if needed
done scrolling
checking that element receives pointer events at (485.95,278.14)
… intercepts pointer events
Please see below the HTML for this:-
<div class="ant-table-filter-column"><span class="ant-table-column-title"><div class="ant-table-column-sorters"><span class="ant-table-column-title">Received Date</span><span class="ant-table-column-sorter ant-table-column-sorter-full"><span class="ant-table-column-sorter-inner"><span role="img" aria-label="caret-up" class="anticon anticon-caret-up ant-table-column-sorter-up active"><svg viewBox="0 0 1024 1024" focusable="false" data-icon="caret-up" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M858.9 689L530.5 308.2c-9.4-10.9-27.5-10.9-37 0L165.1 689c-12.2 14.2-1.2 35 18.5 35h656.8c19.7 0 30.7-20.8 18.5-35z"></path></svg></span><span role="img" aria-label="caret-down" class="anticon anticon-caret-down ant-table-column-sorter-down"><svg viewBox="0 0 1024 1024" focusable="false" data-icon="caret-down" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M840.4 300H183.6c-19.7 0-30.7 20.8-18.5 35l328.4 380.8c9.4 10.9 27.5 10.9 37 0L858.9 335c12.2-14.2 1.2-35-18.5-35z"></path></svg></span></span></span></div></span><span role="button" tabindex="-1" class="ant-dropdown-trigger ant-table-filter-trigger"><span role="img" aria-label="search" class="anticon anticon-search"><svg viewBox="64 64 896 896" focusable="false" data-icon="search" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M909.6 854.5L649.9 594.8C690.2 542.7 712 479 712 412c0-80.2-31.3-155.4-87.9-212.1-56.6-56.7-132-87.9-212.1-87.9s-155.5 31.3-212.1 87.9C143.2 256.5 112 331.8 112 412c0 80.1 31.3 155.5 87.9 212.1C256.5 680.8 331.8 712 412 712c67 0 130.6-21.8 182.7-62l259.7 259.6a8.2 8.2 0 0011.6 0l43.6-43.5a8.2 8.2 0 000-11.6zM570.4 570.4C528 612.7 471.8 636 412 636s-116-23.3-158.4-65.6C211.3 528 188 471.8 188 412s23.3-116.1 65.6-158.4C296 211.3 352.2 188 412 188s116.1 23.2 158.4 65.6S636 352.2 636 412s-23.3 116.1-65.6 158.4z"></path></svg></span></span></div>
Below are the xpaths which I have tried:-
//*[text()='Received Date']/following-sibling::span/span/span[#aria-label='caret-up']
//thead/tr[1]/th[4]/div[1]/span[1]/div[1]/span[2]/span[1]/span[1]
//span[contains(text(),'Received Date')]/following-sibling::span/span/span[#aria-label='caret-up']
Code for clicking - await this.page.locator("//span[contains(text(),'Received Date')]/following-sibling::span/span/span[#aria-label='caret-up']").click();
Please, try to avoid very long or complex Xpaths. They make your code unreadable, they can make errors and they are not the right way to find elements and click on them.
Tell me if this works for you:
button = self.page.locator('//span[contains(text() \
,'Received Date')]').first
button.click()

Screen doesn't change after pressing a button in Xcode simulator

My Kivy app work fine in python2. Running in Xcode (10.1) simulator gives me the main screen, but pressing button does not bring me to the second one (drawing screen). Interestingly when moving and pressing on the mouse, the app print the coordinates as it should.
I've tried create a very simple project with only 1 button and 2 screens: again, on python works OK but in the simulator not.
Any suggestions?
python
class MainScreen(Screen):
username = ObjectProperty(None)
test_type = ObjectProperty(None)
test_date = ObjectProperty(None)
def reset(self):
self.username.text = ""
self.test_type.text = ""
self.test_date.text = ""
class SecondScreen(Screen):
pass
class AnotherScreen(Screen):
pass
class ScreenManagement(ScreenManager):
pass
class DrawInput(Widget):
def on_touch_down(self, touch):
timing_ms = ApplePenApp.get_running_app().sw_seconds
print('test')
with self.canvas:
Color(0, 0, 0)
touch.ud["line"] = Line(points = (touch.x, touch.y))
def on_touch_move(self, touch):
timing_ms = ApplePenApp.get_running_app().sw_seconds
touch.ud["line"].points += (touch.x, touch.y)
def on_touch_up(self, touch):
timing_ms = ApplePenApp.get_running_app().sw_seconds
presentation = Builder.load_file("applepen_kivy.kv")
class ApplePenApp(App):
def build(self):
return presentation
if __name__=="__main__":
ApplePenApp().run()
Kivy
# File name: main.py
#: import FadeTransition kivy.uix.screenmanager.FadeTransition
ScreenManagement:
transition: FadeTransition()
MainScreen:
id: main
SecondScreen:
AnotherScreen:
<MainScreen>:
name: "main"
#define global variables
username: username
test_type: test_type
test_date: test_date
GridLayout:
cols:1
#organise the window
size: root.width, root.height
GridLayout:
cols: 2
Label:
text: "Username: "
color: 0.5,0.5, 0.5, 1
font_size: 30
TextInput:
id: username
multiline: False
font_size: 30
Label:
text: "Copy/Recall/Recall2: "
color: 0.5,0.5, 0.5, 1
font_size: 30
TextInput:
id: test_type
multiline: False
font_size: 30
Label:
text: "Date: "
color: 0.5,0.5, 0.5, 1
font_size: 30
TextInput:
id: test_date
multiline: False
font_size: 30
Button:
font_size: 30
size_hint: 0.5, 0.5
text: "Submit"
on_press: app.root.current = "drawing"
<SecondScreen>:
name: "drawing"
FloatLayout:
DrawInput:
id: drawing
Button:
font_size: 30
size_hint: 0.2, 0.05
pos_hint: {"x": 0.4, "bottom": 1}
text: "finish"
on_release: app.root.current = "main"

How to extract image metadata using MATLAB?

How can I extract image metadata like exposure, width, height, or bitdepth using MATLAB?
Until recently I was using exifread, but this function no longer exists in the newest MATLAB version.
The other function is imfinfo, but it cannot read the 'EXPOSURE DATA' image.
How can I read the 'exposure' image?
exifread() deprecated 9 years ago. It has been replaced by imfinfo
info = imfinfo(filename) will return all information you want.
From the Matlab reference
Additional fields returned by some file formats:
JPEG and TIFF only — If filename contains Exchangeable Image File
Format (EXIF) tags, then info might also contain 'DigitalCamera' or
'GPSInfo' (global positioning system information) fields.
info.Width, info.Height, info.BitDepth.
The exposuretime as well as all other camera parameters are stored in the 1x1 struct info.DigitalCamera
Here's an example from
https://de.mathworks.com/matlabcentral/answers/146651-missing-functionality-when-using-imfinfo-instead-of-exifread
>> info = imfinfo('img_1771.jpg')
info =
Filename: 'C:\Users\fhempel\Desktop\tmp\img_1771.jpg'
FileModDate: '07-Aug-2014 12:09:45'
FileSize: 32764
Format: 'jpg'
FormatVersion: ''
Width: 480
Height: 360
BitDepth: 24
ColorType: 'truecolor'
FormatSignature: ''
NumberOfSamples: 3
CodingMethod: 'Huffman'
CodingProcess: 'Sequential'
Comment: {}
Make: 'Canon'
Model: 'Canon PowerShot S40'
Orientation: 1
XResolution: 180
YResolution: 180
ResolutionUnit: 'Inch'
DateTime: '2003:12:14 12:01:44'
YCbCrPositioning: 'Centered'
DigitalCamera: [1x1 struct]
ExifThumbnail: [1x1 struct]
>> info.DigitalCamera
ans =
ExposureTime: 0.0020
FNumber: 4.9000
ExifVersion: [48 50 50 48]
DateTimeOriginal: '2003:12:14 12:01:44'
DateTimeDigitized: '2003:12:14 12:01:44'
ComponentsConfiguration: 'YCbCr'
CompressedBitsPerPixel: 5
ShutterSpeedValue: 8.9688
ApertureValue: 4.6563
ExposureBiasValue: 0
MaxApertureValue: 2.9709
MeteringMode: 'CenterWeightedAverage'
Flash: 'Flash did not fire, no strobe return detection function, auto flash mode, f...'
FocalLength: 21.3125
MakerNote: [1x450 double]
UserComment: [1x264 double]
FlashpixVersion: [48 49 48 48]
ColorSpace: 'sRGB'
CPixelXDimension: 2272
CPixelYDimension: 1704
InteroperabilityIFD: [1x1 struct]
FocalPlaneXResolution: 8.1143e+03
FocalPlaneYResolution: 8.1143e+03
FocalPlaneResolutionUnit: 2
SensingMethod: 'One-chip color area sensor'
FileSource: 'DSC'
CustomRendered: 'Normal process'
ExposureMode: 'Auto exposure'
WhiteBalance: 'Auto white balance'
DigitalZoomRatio: 1
SceneCaptureType: 'Standard'
All the information you think you are missing is stored in iminfo, just differently. Most of the parameters you want (including exposure data) are in
info=iminfo(fname);
info.DigitalCamera

DWM Leaks Memory When No Monitor Connected Windows 8

Simply, if no monitor connected and you are doing some "windows" operation on windows 8 embedded, dwm.exe starts allocating memory and never stops.
to regenerate and show you all the problem, i have written an application which is doing "Create a new Form and show it, if there is one created close it first"
public partial class PopupWindows : Form
{
private Timer _t;
private Form _form;
public PopupWindows()
{
InitializeComponent();
this.Size = new Size(500, 500);
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
_t = new Timer();
_t.Tick += (o, ea) =>
{
_form?.Close();
(_form = new Form() { Size = this.Size }).Show();
};
_t.Interval = 1000;
_t.Enabled = true;
}
}
if you run this application and plug out the monitor, dwm start allocating pages
here is the output from pslist -m when the monitor connected
Name Pid VM WS Priv Priv Pk Faults NonP Page
dwm 840 123528 14400 11264 13044 55125 7 212
after some time but still the monitor connected
dwm 840 117144 15808 12732 13044 94051 7 200
disconnecting monitor and dwm.exe start allocating
dwm 840 214660 14444 12664 13044 137409 13 400
below is the output where you can see allocation dwm.exe doing
C:\PSTools>pslist.exe -m|findstr "dwm"
dwm 840 251956 14460 12740 13044 137413 16 477
C:\PSTools>pslist.exe -m|findstr "dwm"
dwm 840 251956 14460 12740 13044 137413 16 477
C:\PSTools>pslist.exe -m|findstr "dwm"
dwm 840 251956 14460 12740 13044 137413 16 477
C:\PSTools>pslist.exe -m|findstr "dwm"
dwm 840 252964 14460 12740 13044 137413 16 479
C:\PSTools>pslist.exe -m|findstr "dwm"
dwm 840 252964 14460 12740 13044 137413 16 479
C:\PSTools>pslist.exe -m|findstr "dwm"
dwm 840 253972 14460 12744 13044 137413 16 481
C:\PSTools>pslist.exe -m|findstr "dwm"
dwm 840 253972 14460 12744 13044 137413 16 481
C:\PSTools>pslist.exe -m|findstr "dwm"
dwm 840 254980 14460 12744 13044 137413 16 483
and this strange act dwm doing never stops till you connect a monitor or doing vnc connection to the computer.
after some time on operation without monitor, every os component starts to complain about memory and a blue screen of death occurs at the end.
let me show you the last one
dwm 840 807516 15624 14216 17240 147413 50 1603
here is the output showing how many minutes my popupwindows.exe running
Name Pid Pri Thd Hnd Priv CPU Time Elapsed Time
PopupWindows 2052 6 4 138 9468 0:00:00.140 0:23:07.332
as you can see, after about 20 minutes without having a monitor on the device, dwm.exe using 807516 bytes VM and 1603 pages.
Acting like what vnc doing (copying whole screen bitmap to application memory regularly) solved the dwm's allocation problem (which i think dwm caches its outputs but no one come and ask for the changes so it keeps all of them in the memory and never cleans).
below is the application which starts hidden and regularly copying screen image into app memory
public partial class HiddenForm : Form
{
IntPtr _this;
private System.Windows.Forms.Timer _timer;
private Bitmap _bmp = null;
public HiddenForm()
{
this.Visible = false;
this.ShowInTaskbar = false;
this.FormBorderStyle = FormBorderStyle.None;
this.HandleCreated += (s, e) => _this = this.Handle;
this.Load += (s, e) => this.Size = new Size(0, 0);
CreateHandle();
CreateControl();
_timer = new System.Windows.Forms.Timer();
_timer.Tick += _timer_Tick;
_timer.Interval = 2000;
_timer.Start();
}
private void _timer_Tick(object sender, EventArgs e)
{
if (Screen.PrimaryScreen == null)
return;
if (_bmp == null)
{
using (Graphics g = CreateGraphics())
{
_bmp = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, g);
}
}
using (Graphics grp = Graphics.FromImage(_bmp))
{
grp.CopyFromScreen(0, 0, 0, 0, _bmp.Size);
}
}
}
here is the output after starting my app
Name Pid VM WS Priv Priv Pk Faults NonP Page
dwm 832 117876 20188 19624 35004 184497 7 185
killing my app with pskill waiting a while
dwm 832 182388 20264 19852 35004 421343 11 317
it starts increasing to re check our app i started it again by typing
C:\HiddenForm.exe
and dwm.exe memory allocation magically downed.
dwm 832 126384 27900 27364 35144 556729 7 187

Xcode - Terminating with uncaught exception of type NSException when a button is pressed

I'm new to app development and I'm following Apple's tutorial to learn. I've looked through a lot of questions asked about this type of error but none of them are helping me. In the tutorial, I'm stuck on the "Add Buttons to the View" section where I'm trying to implement a string to be printed out on the console when a button is tapped/clicked on. Only I get an error when doing so.
My code for the button in Swift:
import UIKit
class StarRatingControl: UIView {
// MARK: Initialization
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
let button = UIButton(frame: CGRect(x: 0, y: 0, width: 44, height: 44))
button.backgroundColor = UIColor.cyanColor()
button.addTarget(self, action: "ratingButtonTapped", forControlEvents: .TouchDown)
addSubview(button)
}
override func intrinsicContentSize() -> CGSize {
return CGSize(width: 240, height: 44)
}
// MARK: Button Action
func ratingButtonTapped(button: UIButton) {
print("Button pressed!")
}
}
The error:
2015-09-16 12:43:17.409 FoodTracker[954:13341] -[FoodTracker.StarRatingControl ratingButtonTapped]: unrecognized selector sent to instance 0x7f939b7a43b0
2015-09-16 12:43:17.443 FoodTracker[954:13341] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[FoodTracker.StarRatingControl ratingButtonTapped]: unrecognized selector sent to instance 0x7f939b7a43b0'
*** First throw call stack:
(
0 CoreFoundation 0x00000001079f59b5 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x00000001095f4deb objc_exception_throw + 48
2 CoreFoundation 0x00000001079fdfdd -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x000000010794b9fa ___forwarding___ + 970
4 CoreFoundation 0x000000010794b5a8 _CF_forwarding_prep_0 + 120
5 UIKit 0x0000000108214522 -[UIApplication sendAction:to:from:forEvent:] + 92
6 UIKit 0x0000000108373c06 -[UIControl sendAction:to:forEvent:] + 67
7 UIKit 0x0000000108373eac -[UIControl _sendActionsForEvents:withEvent:] + 273
8 UIKit 0x0000000108372b1c -[UIControl touchesBegan:withEvent:] + 261
9 UIKit 0x000000010827bf50 -[UIWindow _sendTouchesForEvent:] + 308
10 UIKit 0x000000010827cd4d -[UIWindow sendEvent:] + 865
11 UIKit 0x00000001082312ae -[UIApplication sendEvent:] + 263
12 UIKit 0x000000010820d36c _UIApplicationHandleEventQueue + 6693
13 CoreFoundation 0x0000000107921b21 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
14 CoreFoundation 0x0000000107917a4c __CFRunLoopDoSources0 + 556
15 CoreFoundation 0x0000000107916f03 __CFRunLoopRun + 867
16 CoreFoundation 0x0000000107916918 CFRunLoopRunSpecific + 488
17 GraphicsServices 0x000000010befead2 GSEventRunModal + 161
18 UIKit 0x000000010821299e UIApplicationMain + 171
19 FoodTracker 0x00000001078118dd main + 109
20 libdyld.dylib 0x000000010a11392d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
I understand that Xcode keeps old references to action/outlets that I've deleted so I tried right-clicking on the View Controller in the Interface Builder to find items with the exclamation point next to them but I couldn't find anything(only troubleshooting method I know of so far). I'm using Xcode beta 7.0. Any help is appreciated!
You're missing the ":" in the selector, try the following instead:
button.addTarget(self, action: "ratingButtonTapped:", forControlEvents: .TouchDown)
I hope this help you.
If you're using Swift 3, the line in question would have to be changed to:
button.addTarget(self, action: #selector(StarRatingControl.ratingButtonTapped), for: .touchDown)
I had the same problem,
Check the version of your Xcode.
#selector comes with Xcode 7.3
If you have an older version update and this will probably fix your errors.
Regards,
Driss
For reference, I've decided to have a look at the sample and got a similar issue.
I'm using XCode 8 + Swift 3 and these are my changes in order to get it working:
button.addTarget(self, action: #selector(RatingControl.ratingButtonTapped), for: .touchDown)
Note: considering the file name "RatingControl.swift".
I hope it help =D

Resources