IOS Application Freezes - iphone

My application is freezing with a reason that I could not figure out, it does not crash but it freezes.
basically what I did was having another view inside my view that is hidden at first place, after when I click a button this view will be appeared and it includes a UItextfield and a UIPickerView. the pickerview data is updating while I edt the UItextfield and I select one of the values from picker view then basically press addButton, when I add thi whole view will be hidden again and the selected value of the pickerview will be added another UITextfield in the main view.
when I do this first time it works fine. it sets the value of the UI textfield which is on the main view to the correct value. but when I try to change it, get that view unhidden and select another value in the pcikerview and press on addButton again the application freezes. No crash appears.
I want to inform you about this the value of the UITextfield on the main view is changing I checked it on the logs. and the method that do the clicking action completely works. But it freezes.
I couldnt figure it out, I need some help :)
EDIT:
I figure out that the UITextField on the main view cause this freeze, when I set the text
[myTextfield setText:#"somethng"];
the UI freeze. when I comment this out it works pretty fine. But It works fine at first time. does not work on the second time.
Any help will be appreciated.
EDIT 2 (I added some code):
-(IBAction)addButtonClicked:(id)sender
{
leftBarButton = [[UIBarButtonItem alloc] initWithTitle:#"Done" style:UIBarButtonItemStylePlain target:self action:#selector(pickerViewDoneClicked:)];
[[self.navigationController.navigationBar.items objectAtIndex:0] setLeftBarButtonItem:leftBarButton];
[self.pickerContainer setHidden:NO];
}
-(IBAction)pickerViewDoneClicked:(id)sender
{
[[self.navigationController.navigationBar.items objectAtIndex:0] setLeftBarButtonItem:nil];
NSLog(#"%#", self.myTextField);
NSLog(#"old val %#", self.myTextField.text);
// the text field on the main view.
[self.myTextField setText: selectedText];
NSLog(#"new val %#", self.myTextField.text);
[self.pickerContainer setHidden:YES];
}
//in picker view source
selectedText = [pickerData objectAtIndex:row];
As I told the first time I add it works fine I can see the value on the textfield
but when I do the same action again and click done the app freezes.
I checked the reference of the textfield before after and no reference missing
I can see the new value and old value as well. but the UI freezes.

Just to be sure: you do not perform any call to UIKit on non-main thread?

I was using this piece of code for padding for my text field,
UIView *paddingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 15, 20)];
self.myTextField.leftView = paddingView;
self.myTextField.leftViewMode = UITextFieldViewModeAlways;
I am not sure how it effects it but second time I change the text into the textfield I was getting my screen freezed.
Thanks again for any effort to help me.

Related

UIToolbar items disappear - Weird bug in ios6

This is the current setup.
I have the navigationController's toolbar with 5 buttons, and tapping on them hides the toolbar for 2 seconds, and then shows the toolbar again (except the 5th button - which brings up an actionsheet with buttons (ACTION & CANCEL)).
On tapping on the 1-4 buttons, I do a self.navigationController.toolbarHidden = YES; and after exactly 2 seconds, I set the self.navigationController.toolbarHidden = NO; and this brings back the toolbar, and everything's fine.
On tapping the 5th button, which brings up action sheet.
If i tap on CANCEL actionsheet => actionSheet dismissed => Toolbar is fine.
If I tap on ACTION button I do a self.navigationController.toolbarHidden = YES; and after 2 seconds... self.navigationController.toolbarHidden = NO;
but now... The toolbar buttons are GONE.
Further investigating...
I can see the the toolbarButtons seem to have their alpha values set to 0.
I have no idea why the toolbar items' alpha are set to value = 0 after actionsheet operation.
Can anyone tell me the root cause for this?
Have you tried setting the toolbar items array to nil? I had this same problem and it turned out that putting a check around when you set the toolbar's items seemed to work:
if ([self.navigationController.toolbar.items count] > 0) {
[self.navigationController.toolbar setItems:nil];
}
[self.navigationController.toolbar setItems:toolbarItems]; //toolbarItems is your array of UIBarButtonItems.
I managed to fix the issue in a different way. I hide the toolbar when the action sheet comes up, and after the buttonAction(), I essentially show the toolbar again.
This solves the problem where the toolbarItems disappear.
But the reason as to why the toolbarItems disappear and set alpha=0 is still a mystery for me. If anyone finds out the reason, please let me know :)
I had the same issue and reproduced it in one of the samples. It appears to be a bug in iOS6 when setting up toolbar items manually in loadView / viewDidLoad, then later calling an ActionSheet.
The code below is a workaround it -
-(void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
{
NSArray* items = self.toolbarItems;
[self setToolbarItems:nil];
[self setToolbarItems:items animated:NO];
}
I solve it by moving action code to separate method and then calling it through sending message performSelector:withObject:afterDelay: with 0.25f second delay
Example:
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0) {
[self performSelector:#selector(logout) withObject:nil afterDelay:0.25f];
}
}
I don't know if it's the case, I found out that the disappeared items were actually in the toolbar, but placed over the bottom of the view. Maybe resetting them on certain circumstances may cause autolayout issues.
I fixed it by calling the setNeedLayout method on the viewcontroller's view (not the navigationControllers')
self.toolbarItems = toolButtons;
[self.view setNeedsLayout];

UIDatePickerView as FirstResponder for UITextField is missing Month Component

I'm implementing a table view where for one particular table view cell, there is a textfield whose first responder needs to be a UIDatePicker. I've been able to implement most of it, but for some reason the view is not appearing completely correct. I've been stuck on this problem for a while and I've been looking at this answer for help.
UIDatepicker in UItextfield in UItableView
As of now, I have the data picker appearing and disappearing properly, the delegate for the text field is working properly, and the textfield can be updated. My problem is that for some reason the Month component of the date picker is missing (I have a picture, but since I have less than 10 rep, I can't post it). What it looks like is a typically UIDatePicker but the first component that has the months, is completely empty and can't scroll. The day and year components operate normally.
This is how I create the picker view
cell = [tableView dequeueReusableCellWithIdentifier:InfoIdentifier];
UILabel *textLabel = (UILabel *)[cell viewWithTag:kInfoLabelTag];
UITextFieldWithIndex *cellText = (UITextFieldWithIndex *)[cell viewWithTag:kInfoTextboxTag];
cellText.indexPath = indexPath;
textLabel.text = #"Birthday";
UIDatePicker *datePicker = [[UIDatePicker alloc] init];
datePicker.datePickerMode = UIDatePickerModeDate;
[datePicker addTarget:self action:#selector(datePickerValueChanged:) forControlEvents:UIControlEventValueChanged];
datePicker.tag = indexPath.row;
cellText.inputView = datePicker;
And here is the callback method
-(void)datePickerValueChanged:(id)sender {
NSLog(#"Date Changing");
currentTextField.text = #"new date";
}
Resigning the first responder works, and if I print the date, the month is present, so the only problem is that the month labels are missing.
I created this project using Storyboards, and I am also using core date in this project. However, the core data part of this view controller hasn't been implemented yet.
Any ideas?
So after looking through my code more I figured out that the problem was a category I created for a UIPickerView.
In another file, I created a custom picker view by using a category to override the drawrect: method of UIPickerView. In the overrided method, I actually set some of the views as hidden for a UIPickerView. Although the category was only imported in the other file, the category overrided method was being used for UIDatePickerView, and thus setting the first component as hidden.
My quick fix was to simply subclass UIPickerView for my special picker in the other file, thus isolating the custom drawRect override there. After I did this, my UIDatePicker displayed properly!

SSCollectionView SSCollectionViewItem - no Items displayed

I ran into difficulties with SSCollectionView and SSCollectionViewItem.
First of all I'd like to get it initialized from IB. But that won't work for me.
I have a SelectFooViewController which is:
#interface SelectFooViewController : SSCollectionViewController { ... }
and am using it as filesOwner of the corresponding XIB.
SelectFooViewController* selectFooVC = [[SelectFooViewController alloc]
initWithNibName:#"SelectFooViewController" bundle:nil];
But since it wont work I had to initialize its properties inside viewDidLoad() myself.
Furthermore I am not able to display anything except the backgroundColor of my SSCollectionViewItems. What I want is a textLabel and an image .
- (SSCollectionViewItem *)collectionView:(SSCollectionView *)aCollectionView itemForIndexPath:(NSIndexPath *)indexPath {
SSCollectionViewItem *item = [[[SSCollectionViewItem alloc] initWithStyle:SSCollectionViewItemStyleImage reuseIdentifier:itemIdentifier] autorelease];
SSLabel* label = [[SSLabel alloc] init];
[label setText:#"foo"];
item.imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"foo.png"]];
item.textLabel = label;
[label autorelease];
return item;
}
I can confirm that the delegate methods (for determining the number Of rows, sections and such) are implemented and working as expected. But my items are all empty - but react onclick with the expected popup.
Does anyone see an error in what I did? - Thanks...
EDIT: I was also not able to display a local image by changing SSCatalog project
I just figured out, that I have to set the frame of each property (textLabel, detailTextLabel and imageView) myself. That fixed it.
When you create instance SelectFooViewController just insert this line
selectFooVC.view;
or
selectFooVC.view.hidden = NO;
And then add it to the view.
This is because the view is not initalised until you explicitly access it. Hence your items are loaded only when you click it and not immediately. You can call it a hack but i don't call it one. :-)

Popover does not open over button

The layout...
I have a UIToolbar that loads a view with several buttons. One of those buttons, on the onpress should display a popup.
It does. However, the popup seems to open up at 0,0.
-(IBAction)FilterButtonPressed:(id)sender
{
if (_FilterViewController == nil) {
self.FilterViewController = [[[FilterViewController alloc] initWithStyle:UITableViewStylePlain] autorelease];
_FilterViewController.filterViewDelegate = self;
self.FilterViewPopover = [[UIPopoverController alloc] initWithContentViewController:_FilterViewController];
}
NSLog(#"Button...: %#",NSStringFromCGRect(self.FilterButton.frame));
[self.FilterViewPopover presentPopoverFromRect:self.FilterButton.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
The NSLog reads:
Button...: {{0, -4.38184}, {0, 4.76182e-39}}
which is... just weird..
Any suggestions as to why the FilterButton doesn't know where it is?
Any suggestions as to why the FilterButton doesn't know where it is?
Looks like it's uninitialized / not properly initialized. Are all your outlets set up properly? Whenever "my xyz object is not behaving properly" happens, checking your outlets is usually the first order of business (note that the action can be hooked up from a button, but your link to the button from your class may not be. Try printing the state from the "sender" cast to "UIButton *".

uniimageview not updating after views tranistion

I have one main view where I display an image, in the method viewDidLoad:
ballRect = CGRectMake(posBallX, 144, 32.0f, 32.0f);
theBall = [[UIImageView alloc] initWithFrame:ballRect];
[theBall setImage:[UIImage imageNamed:#"ball.png"]];
[self.view addSubview:theBall];
[laPalla release];
Obviously, the value of posBallX is defined and then update via a custom method call many times in the same class.
theBall.frame = CGRectMake(posBallX, 144, 32, 32);
Everything works, but when I go to another view with
[self presentModalViewController:viewTwo animated:YES];
and come back with
[self presentModalViewController:viewOne animated:YES];
the image is displayed correctly after the method viewDidLoad is called (I retrieve the values with NSUserDefaults) but no more in the second method. In the NSLog I can even see the new posBallX updating correctly, but the Image is simply no more shown...
The same happens with a Label as well, which should print the value of posBallX.
So, things are just not working if I come back to the viewOne from the viewTwo... Any idea???????
Thanks so much!
You should use dismissModalViewControllerAnimated: to switch back to viewOne from viewTwo instead of trying to present viewOne modally.
Also note that viewDidLoad is called only once - after the view controller's view is loaded into memory. If you want to perform an action once a view comes back on screen, you should do so in viewWillAppear:.
Both of these points are discussed in the UIViewController class reference and in the View Controller Programming Guide.