Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I have set the placeholder text(e.g. Under 18s) of a text field(homeTeam) in storyboard. Now i want to check the condition something like below.
- (BOOL)textFieldShouldBeginEditing:(UITextField *) textField
{
if ([_homeTeam.text isEqualToString:#"e.g. Under 18s"]) { // e.g. Under18s
[_homeTeam setPlaceholder:#""];
}
}
But the condition is never getting true. What am i missing here? _homeTeam.text is blank when i used NSlog to trace. Why is it so?
Please suggest.
change your if condition, it should be _homeTeam.placeholder not _homeTeam.text because you set placeholder text not a text of UITextField.
- (BOOL)textFieldShouldBeginEditing:(UITextField *) textField
{
if ([_homeTeam.placeholder isEqualToString:#"e.g. Under 18s"]) { // e.g. Under18s
[_homeTeam setPlaceholder:#""];
}
}
You actually want to compare against the placeholder property, not text (which is input by the user).
Also, I would instead refer to textField (instead of _homeTeam directly, as you might add other text fields later), as such:
- (BOOL)textFieldShouldBeginEditing:(UITextField *) textField
{
if ([textField.placeholder isEqualToString:#"e.g. Under 18s"]) { // e.g. Under18s
[textField setPlaceholder:#""];
}
}
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I'm loading around 500 rows of data into a List. It was okay when I had 10 rows but now that I have 500 it's extremely slow. Is there anything I can do to help it's performance?
List {
SegmentedControl(selection: $feedType) {
ForEach(FeedType.allCases.identified(by: \.self)) { type in
Text(type.rawValue)
}
}
ForEach(store.stories) { story in
NavigationButton(destination: Text("")) {
StoryRow(story: story)
}
}
}
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
In Objective C we used
if([names count]>1){
// array count is greater than one
}
The same way i tried to check in swift. But the complier shouts.
Any idea??
The correct way to write it should be:
if name.count > 1 {
// Your code here
}
Your syntax is incorrect. Brackets are used in Objective-C, not Swift.
Try this:
var shoppingList = ["Eggs", "Milk"]
if(1 < shoppingList.count) {
println( "Greater than one")
}
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I need to get the current URL loaded into the webview and this is how I'm trying to get that but it gives me this error: "Cannot convert the exporessions type 'ST7??' to type 'String'
and this is the code
var currentURL : NSString = webView.request?.URL.absoluteString!
What is wrong with this?
If you put parentheses around this, the error goes away:
let currentURL : NSString = (webView.request?.URL.absoluteString)!
Beware that yours might not be just a syntax problem.
If your webView is in a state where request == nil your app will crash at runtime.
I'd rather write something like:
if let currentURL = webView.request?.URL.absoluteString {
// do things ...
// Your currentURL will be automatically bridged to Swift's String type
} else {
// Just in case request is nil ...
}
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 9 years ago.
Improve this question
Using addObject is adding the object twice
AppDelegate *appdelegate = [[UIApplication sharedApplication] delegate];
NSLog(#"LOG1 %#", object.text);
[appdelegate.mutarray addObject:object.text];
NSLog(#"LOG2 %#", appdelegate.mutarray);
Log1 returns: LOG1 value
Log2 returns: LOG2 (
"value",
"value"
)
why is it adding in twice? removeObject removes both can i remove just one
Because your first time added your value to NSMutableArray through without remove value from the NSMutableArray going add often. that so far it be adding concurrent duplicate value. before adding new value remove your entire array.
if(appdelegate.mutarray.count!=0)
[appdelegate.mutarray removeAllObject];
[appdelegate.mutarray addObject:object.text];
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
When my UIPickerView View is empty [the array is loads the data from is empty], If I try to select the Picker View the application crashes. What is the solution
I'm not sure but i guess that error generated because your array is empty and you should write any where in delegate method of UIPickerView such like [array objectAtindex....]; so,,
In each statement which you write [array objectAtindex....]; put condition that
if(array.count > 0)
[array objectAtindex....];..
So your picker will open but not generate any error.
EDITED:
I got solution for you:
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
if ([myArray count] == 0)
return 1;
return [myArray count];
}
No need to apply any other condition i was checked it, in my project.
It's due to array out of bound exception it seems.
Check whether you are using any static index value while selecting the values.
e.g [sourceArray objectAtIndex:0]; // It get crash when the source array is empty.