App Crashes when trying to add cells to tableView - iphone

I am using an NSMutableArray to populate my tableView.The array's name is cells. I have a button that adds cells, but when i press the button, the app crashes. The code in my button is:
- (IBAction)outlet1:(id)sender {
[cart.cells addObject:#"1"];
[cart.myTableView reloadData];
}
this button is on a seperate page from the table view, so cart is referring to the tableView page. Any help would be appreciated! Thanks

The exception message means that someone is trying to call a method named outlet1 that has no argument (note the missing colon) while your method's signature is outlet1:. You have probably missed the colon of the selector when adding the target/action to your button.

Related

Working with the UI Table View, iOS 7

I have UI View Table and Simple View controllers in my project. They are connected with each other by navigation controller. At the top of the UI View Table, there is a button "Add new location" that invokes segue to the Simple View. The latter has the text field that has to be filled by the user. When the user taps the "Back" button then he/she has to see the "updated" UI Table View with the newly added cell.
In order to pass data between these view, I am using singleton class (from my point of view, that perfectly fits the MVC paradigm). This object has NSMutableArray as the property that updates when user has finished typing the at the text field at the Simple View controller.
However, when I launch the application at the first time, press the Add new location button, enter the text at the text field and hit back - nothing happens i.e. the UI Table doesn't update.
But, when I repeat the same steps again, two (the same) cells are added to the UI Table View.
Could you please hint me how can I fix this issue i.e. add only one cell to the UI Table view when user presses Back button?
This is because -(IBAction)textFieldReturn:(id)sender is triggered twice. You've to put the method to add the data in your viewWillDisappear:(BOOL)animated, with a check for null values:
-(IBAction)textFieldReturn:(id)sender{
}
-(void)viewWillDisappear:(BOOL)animated {
if ([_textSearch.text length] == 0) return;
NSLog(#"%#", _textSearch.text);
_info.isEdited=YES;
_info=[GeoChatInformationAboutTheSelectedPlace returnInstance];
[_info.arrayOfTheNamesOfTheLocations addObject:_textSearch.text];
[_info.imagesOfTheSavedLocations addObject:#"car1.jpeg"];
[_info.arrayOfTheNumberOfUpdatesOfTheSavedLocations addObject:#"1"];
[_info.arrayOfTheOnLineUsersAtTheSavedLocations addObject:#"56"];
[_info.arrayOfThePostsAssociatedWithTheSelectedLocation addObject:#3];
}
You've to reload the UITableView data source in viewWillAppear:animated method of your tableview view controller:
- (void)viewDidLoad
{
[super viewDidLoad];
_info=[GeoChatInformationAboutTheSelectedPlace returnInstance];
//[self.tableView reloadData];
}
-(void)viewWillAppear:(BOOL)animated {
[self.tableView reloadData];
}
ps: car1.jpeg and car2.jpeg are missing in your github project

How to reload the UIViewController

Can anyone please tell me how to reload the view.In my program,it contain a tab view controller.There is one item named "A" in the tab.And this "A" item is pointing to a viewController.In that view Controller, it is displaying some datas and I have included UIActionSheet in that. There is one button-Delete in the actionsheet.This delete button is for deleting the particular data.Now my problem is that I need to reload that view so that these deleted data should not be displayed. So anyone please tell me how to reload the page. I have included the following code before
[self presentModalViewController:historyView animated:YES];
[historyView setNeedsDisplay];
but it is showing some error :-
No visible #interface for viewcontroller declares the selector 'setNeedsDisplay'
Please tell me the solution.. :(
UIViewController class doesn't have a method setNeedsDisplay. The UIView class does have this method. So you can write like that:
[historyView.view setNeedsDisplay];
But this method doesn't reload a view. It just marks the receiver’s entire bounds rectangle as needing to be redrawn (from apple documentation iOS Developer Library). So as a result the drawRect method will be called.
To solve your problem you can create your own function like initializeUI in your view controller and then call it when the view is loaded initially (in viewDidLoad method) and for example after deleting the data when you need the view to be updated.

UIKeyboardWillShowNotification issue

This is the flow of my app. 1st view -> 2nd View -> 3rd View
On 3rd view, when I click on any row of tableView one UIView gets displayed, which has one textField which accepts only numbers. For this I have implemented UIKeyboardWillShowNotification and displayed a UIButton for 'dot' button on the down-left corner of keyboard (For this I have created two images and sets that image to UIButton object).
My problem is, After using this custom keyboard(for 2-3 times), when I redirect form 3rd view to 1st View, This UIButton (with dot image) is appearing on 1st view. I have used default keyboard at there but this image not getting away.
While moving from 3rd view to 1st view, I m removing Observer for the keyboard notification which I have registered earlier & also I m checking wether,
if ([dotButton retainCount] > 0) {
[dotButton release];
dotButton = nil;
}
I have allocated dot button only once in viewDidLoad.
I m using popToRootViewController method to go back to 1st view from 3rd view.
I dont want to display this dot button on my 1st view. How can I do this.
Follow this steps
1) First make the doneButton an instance varible of your class, this will help u maintain the reference to the button
2) Add this code at the beginning of ur keyboardWillShow:(NSNotification *)note method
if(dotButton){
[dotButton removeFromSuperview];
dotButton = nil;
}
and one more thing implement UIKeyboardWillHideNotification method with NSNotificationCenter and perfrom step 2 over there.
I assume when you created the dotButton, you are calling addSubview: to put it on the screen.
When you want to remove it, you need to remove by calling [dotButton removeFromSuperview]. If you just release it, it will still be retained by the view that is containing it.
Finally, you should NEVER be calling retainCount unless you are debugging something. I've been writing Objective-C code for years and I have NEVER used retainCount, even when I was doing weird runtime stuff.
The rule is simple. If you need an object to stick around, you call retain. When you are done with it, you call release. If somebody else has retained it that's none of your business.

application crashes on calling popViewController : error: alertView:didDismissWithButtonIndex:

A description of the problem is as follows:
I have a view, say, view A. To enter certain data, I have an alert,with a text field inside it, which pops up. Once the user enters data into the text field, i have an alertView:didDismissWithButtonIndex: function as follows :
- (void)alertView:(UIAlertView *)alertView:didDismissWithButtonIndex:(NSInteger)buttonIndex {
[ amountEntered resignFirstResponder]; //dismiss keyboard
if (buttonIndex == 1) { //OK clicked, do something
if(lblShowTypedText.text)
data.investmentAmount = lblShowTypedText.text ;
[myTable reloadData];
}
}
Then I have a submit button on my View A, which when clicked pops back to the previous view. Here is where my app crashes. There is no message in the console, however after many runs, I got one message like this:
* -[NSCFType alertView:didDismissWithButtonIndex:]: unrecognized selector sent to instance 0x3c4dce0
2010-06-24 15:33:22.970 BankingAppln[2895:207] CoreAnimation: ignoring exception: * -[NSCFType alertView:didDismissWithButtonIndex:]: unrecognized selector sent to instance 0x3c4dce0
Thus i have narrowed down the problem to the alertView:didDismissWithButtonIndex: function. If I do not call the alert, but directly pop back to the previous view, everything is fine.
I must be doing something wrong in my alertView:didDismissWithButtonIndex: function.
Pls help!!
A few things to check:
You set the delegate of the AlertView to the right class (View A)?
Your class (View A) implements the UIAlertViewDelegate protocol.
Probably not, but you never know: You're classname is not equal to a name in apple's private api (don't laugh, happened to me a week ago, costed me 2 hours to figure out)?
EDIT:
Another thing to check:
Your delegate method has the right return type (I think it's "void" in that case)?
Do you really have this method, alertView:didDismissWithButtonIndex:, in your class? and post the code when you call it as well
You need to post where you call the method..but from the error message you gave, the problem is you are calling your method incorrectly.
if it is a method you defined yourself with the implementation above use
[self alertView:myAlertView didDismissWithButtonIndex:myIndex];
also, in your declaration, you have a semicolon after the parameter alertView and you just need a space.
I faced a similar problem and it turns out that with Automatic Reference Counting in place, I needed to keep a reference to the popup around as a property so that it would not be reference collected. That much was fine but I got overzealous and started doing stuff like popup = nil; explicitly and that got me into trouble because some of the delegate methods for the popup were called after I had nil'ed out the reference that I was holding onto and now this popup was not around anymore and the framework crashed due to this little fact.
[__NSCFString alertView:didDismissWithButtonIndex:]: unrecognized selector sent to instance 0x9117c0
So I decided to simply keep allocating a new popup when it was needed and not explicitly nil'ing out the older references. This fixed the issue for me.

Problem reloading UITableView

I have a UITableView which is populated by an array, I have a button on the navigaton bar which (when pressed) adds an item to the array and calls [self.tableView reloadData] in the UITableView. This results in numberOfRowsInSection being called and returning the correct number of rows (the number of items in the array) BUT doesn't call cellForRowAtIndexPath.
I have created a new navigation based application to try and find a solution but have exactly the same problem!
If anyone knows the answer it would be greatly appreciated, i've been tearing what's left of my hair out for the last day!
I have put the source for the test project up on my site at www.sofaracing.com/Downloads/Test3.zip
Works for me! ;)
In MainWindow.xib, You added an object Root View Controller (that's not part of the Navigation Controller) - Delete it, not necessary. Then connect outlet refreshFriendsList to the Bar Button of the NavigationItem of RootViewController. Wha-la, magic!
BTW: You may need to clean up the warning. And you might want to think about creating a class for your data model instead of using UIApplication sharedApplication.
I quickly debugged your test app. I couldnt't spot the root cause, but it seems that you have two different table views due some mess up in Interface Builder setup.
If you initialize original array with an item, cellForRowAtIndexPath is correctly called. If you examine self.tableView instance in this call and later in subsequent calls to refreshFriendsList, self.tableView points to a different instance.
2009-05-17 14:33:07.591 Test3[33580:20b] cellForRowAtIndexPath 0
2009-05-17 14:33:07.594 Test3[33580:20b] self.tableView: <UITableView: 0x52b9b0>
2009-05-17 14:42:36.810 Test3[33762:20b] numberOfRowsInSection: tableView <UITableView: 0x53bcd0>