|
|
#1 |
|
Need help with a UITextField method *help*
What I'm trying to do is make it so after they press done on the pop up keyboard, if the text is nil...no object is added to the array, but if its not nil then create the object and add it to the array.
Heres the code I have Code:
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
if (!self.theList)
{
self.theList = [[NSMutableArray alloc] init];
}
Paper *newItem = [[Paper alloc]init];
newItem.listName = textField.text;
if (newItem.listName == nil)
{
[textField resignFirstResponder];
[self.collectionView reloadData];
}
else {
[self.theList addObject:newItem];
textField.text = nil;
NSLog(@"Count %d",self.theList.count);
[textField resignFirstResponder];
[self.collectionVIew reloadData];
}
return YES;
}
__________________
-= My Macs =-
*2011 Mac Mini, 2.7 GHz i7, 16gb RAM, 256gb SSD* *2012 Macbook Air 1.8 GHz i5, 8gb RAM, 128 SSD* |
|
|
|
0
|
|
|
#2 |
|
What's wrong with the code you already have? In order for anyone to help you with something, you have to tell us what's not working.
|
|
|
|
0
|
|
|
#3 |
|
Why would the text ever be nill?
You should check if the string equals @"" (an empty string.) Actually, there might even be an NSString method to directly test if it's an empty string... |
|
|
|
0
|
|
|
#4 |
|
I fixed the problem.
I just made an NSString = @"" and then compared my list object to the string and if it was equal then it wasn't added to the array
__________________
-= My Macs =-
*2011 Mac Mini, 2.7 GHz i7, 16gb RAM, 256gb SSD* *2012 Macbook Air 1.8 GHz i5, 8gb RAM, 128 SSD* |
|
|
|
0
|
|
|
#5 |
|
You could also test the the Length of the string.
Code:
if (textView.text.length !=0)
{
//Do Stuff
}
__________________
There is no such thing as "Collective Wisdom" [13" MacBookPro 2.7Ghz, 27"Al iMac i7, Black MacBook 13", iPhone 4, iPad] |
|
|
|
0
|
|
|
#6 |
|
Testing the length is MUCH more efficient than string comparison. String comparison is fairly compute-intensive.
__________________
Regards, Duncan Champney, WareTo. Check out our latest app, Face Dancer, available for free on the App Store. |
|
|
|
0
|
|
|
#7 |
|
|
0
|
|
|
#8 |
|
ahhh I see. I'll change it up to do that, thanks a bunch.
__________________
-= My Macs =-
*2011 Mac Mini, 2.7 GHz i7, 16gb RAM, 256gb SSD* *2012 Macbook Air 1.8 GHz i5, 8gb RAM, 128 SSD* |
|
|
|
0
|
|
|
#9 |
|
How is length determined? I was under the impression that NSStrings weren't much different from C-strings, which would then mean length is determined by checking each character and seeing if it's a \0 or not... If it's going character by character either way, I don't see why length would be any faster?
|
|
|
|
0
|
|
|
#10 | ||
|
Quote:
Quote:
Also it seems that all NSObjects maintain an Instance size in Bytes* it would seem like the length of the string in characters would be simple function of the size. Not to mention that to comparing two strings you need two objects where as length is standalone. *fun reading MacDevCentre -inside Objective-c runtime
__________________
There is no such thing as "Collective Wisdom" [13" MacBookPro 2.7Ghz, 27"Al iMac i7, Black MacBook 13", iPhone 4, iPad] |
|||
|
|
0
|
|
|
#11 | |
|
Quote:
1. Create a string of 10 million characters. 2. Create a 2nd string that's the same 10 million characters plus an 'X'. 3. Create a 3rd string that's the same 10 million characters plus a 'Y'. 3. Perform isEqual: across the three strings. If the length-first hypothesis is correct, it should be noticeably faster when the lengths differ, and noticeably slower when the lengths are the same. Any sufficiently large value would work, 10 million is just an example. |
||
|
|
0
|
|
|
#12 | |
|
Quote:
The code: Code:
if ([field.text length] == 0) Finally, checking that the length == 0 is really easy to read and maintain.
__________________
Regards, Duncan Champney, WareTo. Check out our latest app, Face Dancer, available for free on the App Store. |
||
|
|
0
|
![]() |
|
«
Previous Thread
|
Next Thread
»
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
All times are GMT -5. The time now is 02:57 PM.








Linear Mode
