I have face strange problem on UIButton.
When i tap button the app is crash .
I wrote below code for that...
-(IBAction)renameTest:(id)sender
{
NSLog(#"Tapped");
// UIButton *button = (UIButton *)sender;
NSUInteger row = 1;//button.tag;
NSString * titlename = [titleArray objectAtIndex:row];
RenameTest *renameVC = [[RenameTest alloc]initWithNibName:#"RenameTest" bundle:nil];
renameVC.titlespell = titlename;
NSLog(#"titlespell = %#",renameVC.titlespell);
NSLog(#"title = %#",titlename);
// [button release];
[self.navigationController pushViewController:renameVC animated:YES]; //here APP is cresh
[renameVC release];
}
I check also my .Xib file name .It is ok and files are there.
error msg is below :
2012-07-11 14:28:29.079 TestApp[238:207] -[__NSCFDictionary _isNaturallyRTL]: unrecognized selector sent to instance 0x73d8a80
Thanks in Advance.
[button release] is causing the problem. Remove it and check.
_isNaturallyRTL is an NSString method (private), and it looks like you are passing a dictionary instead of a string somewhere.
Breaking on the exception and showing us the call stack at that point would help tremendously.
If u have created the button in xib file then u cannot release it because you have not allocated it and claimed ownership.. U should call release only on objects you have allocated by calling alloc..
Remove the [button release] statement .. that should fix the crash!
You have a crash which is related to a dictionary and your titlename string is set equal to, titleArray objectAtIndex:row. I believe, without seeing the declaration of your variables, that titleArray is a dictionary, or is a NSMutableArray importing from a plist of dictionaries, either way you need to use objectForKey, when using dictionaries, like this:
[[titleArray objectAtIndex:(NSUInteger *)] objectForKey:(NSString *)]
Obviously replace (NSUInteger *) with your integer row and (NSString *) with the name of your key. This may not be the answer but from your crash report and visible code, this is what I assume.
Related
I'm having trouble looping through a set of dynamically created UITextFields and storing those values as a double to be added to an array later on. I'm still pretty new to obj-c programming so bear with me if this question seems trivial. Thanks. This is what I have so far.
NSMutableArray *textFieldCashArray = [[NSMutableArray alloc] init];
double textFieldCash;
for (int y=0; y<25; y++) {
UITextField *myLabel = (UITextField *)[self.view viewWithTag:y];
textFieldCash = [myLabel.text doubleValue];
[textFieldCashArray addObject:[NSNumber numberWithDouble:textFieldCash]];
}
P.S and here is the error message I'm getting
Pro[962:b303] -[UIControl text]: unrecognized selector sent to instance 0x680f850
2012-04-01 16:05:46.305 iFinance Pro[962:b303] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIControl text]: unrecognized selector sent to instance 0x680f850'
*** Call stack at first throw:
I think what's going on here is that the loop variable is being used as the tag, and the loop starts at zero. viewWithTag will answer either the receiver or one of it's subviews with a given tag, so if the view controller's main view has tag==0 (which it probably does), your first text request is being sent to that top-level view.
Try setting the text field tags to some non-zero value, starting at SOME_OFFSET. Then in your loop:
for (y=0; y<25; y++) {
UITextField *myLabel = (UITextField *)[self.view viewWithTag:y+SOME_OFFSET];
// ...
}
danh is most certainly right about the cause and solution to this problem. Just to add a little, cases like this can be somewhat avoided by checking the Class before casting.
if ([[self.view viewWithTag:y] isKindOfClass:[UITextField class]]) {
UITextField *myLabel = (UITextField *)[self.view viewWithTag:y];
textFieldCash = [myLabel.text doubleValue];
[textFieldCashArray addObject:[NSNumber numberWithDouble:textFieldCash]];
}
You should create array at first:
NSMutableArray *textFieldCashArray = [NSMutableArray array];
Edit
Your error log shows that you are receiving some another UIControl object (UIBtton for example) instead of UITextField. Check your tags on xib (or algorith if you set programmatically) and be sure that UITextField objects has corresponding tags
I am doing something as simple as get the current title of an UIButton
-(IBAction)buttonPressed:(id)sender{
NSString *someString = [sender currentTitle];
}
For some reason Xcode confuses sender with self because the complete options only retunrns methods that belongs to "self". No matter whatever I do, I get the same
-(IBAction)buttonPressed:(id)sender{
UIButton *btn = (UIButton *)sender;
NSString *someString = [btn currentTitle];
}
Xcode crashes in NSString line with "unrecognized selector sent to btn". I can copy working code from another project and the same happens. What could be wrong?
SOLUTION
Resarted XCode and it worked fine o.O
I don't think Xcode is confusing sender with self, what's happening is that Xcode knows nothing about sender, since it was declared as id, which means Xcode only knows it's an object.
The suggestions you are getting in Xcode are probably just methods every object has.
You have to make sure that sender is what you expect, try doing this and checking if it's actually a button or something else:
-(IBAction)buttonPressed:(id)sender{
NSLog(#"Sender: %#", sender);
}
SOLUTION
Resarted XCode and it worked fine o.O
Possible reason for "unrecognized selector sent to btn" is when you call a method which was not actually written. Or you might be called
[self buttonPressed];
instead of
[self buttonPressed:];
Your problem is your calling the 'id' not the button its self. Replace the 'id' with 'UIButton' like so...
-(IBAction)buttonPressed:(UIButton *)sender{
NSString *someString = sender.currentTitle;
}
I think the problem is wrong syntax
It is
sender.currentTitle;
OR
btn.currentTitle;
currentTitle is a property and there is no function called currentTitle and hence you get the error "unrecognized selector sent to btn".
I have passed an NSArray value back to a parent view using a delegate.
it is received in the parent view like so
- (void) setManufactureSearchFields:(NSArray *)arrayValues withIndexPath:(NSIndexPath *)myIndexPath
{
manufactureSearchObjectString = [arrayValues valueForKey:#"MANUFACTURER"];
NSLog(#"%#",[arrayValues valueForKey:#"MANUFACTURER"]);
manufactureResultIndexPath = myIndexPath;
[self.tableView reloadData]; //reloads the tabels so you can see the value in the tableViewCell.
}
If i was to execute this code and select the tablecell of the childview it obviously executes the delegate but then freezes up and fires this error to the Log
2011-10-31 14:06:16.670 code[12610:207] (
"Alfa Romeo"
)
2011-10-31 14:06:16.673 code[12610:207] *** -[__NSArrayI isEqualToString:]: message sent to deallocated instance 0x6859280
However if I comment out the following line in my delegate method
- (void) setManufactureSearchFields:(NSArray *)arrayValues withIndexPath:(NSIndexPath *)myIndexPath
{
//manufactureSearchObjectString = [arrayValues valueForKey:#"MANUFACTURER"];
NSLog(#"%#",[arrayValues valueForKey:#"MANUFACTURER"]);
manufactureResultIndexPath = myIndexPath;
[self.tableView reloadData]; //reloads the tabels so you can see the value in the tableViewCell.
}
it dose not crash and I end up with the NSLog with the correct details in my log like so.
2011-10-31 14:09:28.200 code[12737:207] (
Sony
)
I am hoping someone has experianced such a problem before, this is what my array object looks like, its a dictionary of values.
ISELECT = F;
ISALIVE = T;
MANUFACTURER = Sony;
MANUFACTURERID = 3;
valueForKey: returns an autoreleased instance. Unless you retain it, you can expect it will be deallocated sometime after you return from the current method. It looks like you are assigning it to an instance variable. If you do that, you need to retain it.
manufactureSearchObjectString = [arrayValues valueForKey:#"MANUFACTURER"];
[manufactureSearchObjectString retain];
But it looks like you have another problem.
[arrayValues valueForKey:#"MANUFACTURER"];
That returns an array.
manufactureSearchObjectString = [arrayValues valueForKey:#"MANUFACTURER"];
By the name of your variable, it looks as though you're assigning it to a string variable. So if you fix the retain issue, then you will have another error. You will get an unrecognized selector when you try to call isEqualToString on it.
You need to assign a string value to manufactureSearchObjectString. You need to figure out what string value you want that to be. In this case you only have one string in your array, so I guess you want that one. In that case
manufactureSearchObjectString = [[arrayValues valueForKey:#"MANUFACTURER"] objectAtIndex:0];
[manufactureSearchObjectString retain];
But in general you need to check if there is more than one value in the array, and decide which one you want, and also check if there are no values in the array, and do something correct to handle that.
Try changing your code into this:
- (void) setManufactureSearchFields:(NSDictionary *)arrayValues withIndexPath:(NSIndexPath *)myIndexPath
{
manufactureSearchObjectString = [[arrayValues valueForKey:#"MANUFACTURER"] copy];
NSLog(#"%#",[arrayValues valueForKey:#"MANUFACTURER"]);
manufactureResultIndexPath = myIndexPath;
[self.tableView reloadData]; //reloads the tabels so you can see the value in the tableViewCell.
}
Please note that I've also changed the variable type of arrayValues to NSDictionary. Let me know if that works for you.
please convert it to NSString.
NSString *manufact=[NSString stringWithFormat:#"%#",[arrayValues valueForKey:#"MANUFACTURER"];
It will not get crash.
i am adding two labels and two image view to subview.
when ever i tap on the button i add this subview to mainview.
I am getting images from the web server and save it in local simulator documents.
NSMutableString *about_name_str = [[NSMutableString alloc]init];
[about_name_str appendString:[myDictionary objectForKey:#"firstname"]];
[about_name_str appendString:#" "];
[about_name_str appendString:[myDictionary objectForKey:#"lastname"]];
[about_name_label setText:about_name_str];
NSMutableString *about_addr_str = [[NSMutableString alloc]init];
[about_addr_str appendString:[myDictionary objectForKey:#"state"]];
[about_addr_str appendString:#","];
[about_addr_str appendString:[myDictionary objectForKey:#"country"]];
[about_addr_label setText:about_addr_str];
about_image.image = [UIImage imageWithContentsOfFile:imagepath];
about_logo.image = [UIImage imageWithContentsOfFile:logopath];
if ([myDictionary objectForKey:#"companyurl"]) {
[about_url_button setTitle:[myDictionary objectForKey:#"companyurl"] forState:UIControlStateNormal];
about_url_button.userInteractionEnabled = YES;
}
else {
about_url_button.userInteractionEnabled = NO;
}
[self.view addSubview:about_view];
this my code.
some times i got Program received signal: "EXC_BAD_ACCESS". and application quits.
i check by placing break points,and in debugger i did n't get where i am getting error.
can any one please help me,How can i resolve this.
Thank u in advance.
Try to use NSZombie.. It is a easy way to find where the EXCBADACCESS occurs...
It will specify which Method where and Which object gets deallocated(Its pretty awesome concept i like in Instruments)...
See this Link
http://www.markj.net/iphone-memory-debug-nszombie/
You should insert a breakpoint before this code is executed then step through it to find the exact line which is causing the bad access. You probably have a null or wild pointer somewhere.
I have 4 UITextFields that I'm dynamically creating, in the viewDidLoad, which works good. I want to reference those objects when the UISlider value changes. Right now I'm storing those objects in a NSMutableArray and accessing them like so from the sliderChanged method:
NSInteger labelIndex = [newText intValue];
labelIndex--;
NSUInteger firstValue = (int)0;
NSMutableArray *holeArray = [pointsArray objectAtIndex:labelIndex];
UITextField *textField = [textFieldArray objectAtIndex:firstValue];
NSString *newLabel1Text = [[NSString alloc] initWithString:[[holeArray objectAtIndex:firstValue] stringValue]];
[textField setText: newLabel1Text];
[newLabel1Text release];
Everything is working good, but the program crashes on the setText: method. The last message I get from the program is: [UILabel drawTextInRect:] and then I get a EXC_BAD_ACCESS failure.
I want to be able to acces that dynamically created UITextField, but I must be going about it the wrong way.
Thanks!
Uh, yea, you create a text field, but you aren't displaying the field itself, just creating it.
If you want to do what I think you want to do, I would just do if statements.
ex.
if (firstValue == 1)
{
fieldone.text = #"whatever";
}
else if (firstValue == 2)
{
fieldtwo.text = #"whatever";
}