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
Related
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.
i have a tough one for you today. I have two tableViews in my app the first is on the first page. There are two other pages the user drills down to get to the second table view. After i leave the first table view, i can press the back buttons to get back perfectly until i reach the second table view. As soon as i drill down to the second table view and then try to return to the first via pressing the back buttons. As soon as i get to the last back button to return to the first table view, the app crashes. The code for the back buttons is simply:
- (IBAction)goBack:(id)sender {
[self dismissModalViewControllerAnimated:YES];
}
Any Help Would be greatly appreciated!! Thanks everyone!! :D
Whenever I create a modal view controller from a XIB, the automatic #property generator duplicates things in the Dealloc method, thus throwing an EXC_BAD_ACCESS when the view is dismissed. Make sure you aren't releasing something twice.
Sounds like your are releasing something too early. Open you app in instruments (command + i) and run a zombie test.
As soon as you see zombie has been messaged expand the right panel and have a look at the user code (your code) blocks. Indicated by the back person icon.
Double click that and it will indicate what it was trying to access that had already been released.
Are your tableviews being displayed in a modal window? If not, why are you calling [self dismissModalViewControllerAnimated:YES]? Shouldn't you be calling [[self navigationController] popViewControllerAnimated:YES]?
If you're using a UINavigationController, the back button functionality should be provided automatically.
if you are using [[self navigationController] popViewControllerAnimated:YES] to
then for back you write as mentioned below:
(IBAction)goBack:(id)sender {
// Tell the controller to go back
[self.navigationController popViewControllerAnimated:YES];
}
if you are using [self presentmodalviewcontroller: animated:]
then only [self dismissModalViewControllerAnimated:YES] will work
you try this [[self navigationController] popViewControllerAnimated:YES]
so I am trying to create an array of recently viewed pictures. Basically I have a TableViewController that pushes a picture view in a navigation controller, located in one tab and then am trying to have a navigation controller that records what pictures have been recently viewed, lists them in a TableViewController and then also pushes that to a new view displaying the picture. I have set up both navigation controllers within the tab bar controller programmatically. Pretty much everything is set up the way I want it but I am just not able to pass the recently viewed picture information to the table view controller that will display the list.
Here is how I am trying to pass the data when a user clicks on a particular table cell:
(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
RecentsTableViewController *rtvc = [[RecentsTableViewController alloc] init];
[rtvc.recents addObject:[self dictionaryAtIndex:indexPath]];
[rtvc release];
}
recents is a mutable array that I created in the RecentsTableViewController. It is getting initialized ok, checked using NSLog, but every time a user clicks on the table cell in the other view controller, the dictionary is not being passed to the array. I also know the dictionary information is correct and set correct because it works passing on to the view that displays the image. I guess I am just confused because I can do it for a NavigationController, I am just struggling to find the answer in passing data in a TabBarController.
Sorry if this post may be long/confusing but I have really searched everywhere for an answer with no luck. I have heard about using the app delegate to store like a global variable but I am under the impression this is bad practice and I am trying to write my code correctly.
Here is the updated code for the dictionaryAtIndex method:
- (NSDictionary *)dictionaryAtIndex:(NSIndexPath *)indexPath {
NSArray *flickrPics = [FlickrFetcher photosAtPlace:self.placeID];
NSDictionary *returnedDictionary = [flickrPics objectAtIndex:indexPath.row];
return returnedDictionary;
}
indexPath is a struct which contains two properties, row and index, and cannot be used directly to access an object in an array. You probably want to do this instead:
[rtvc.recents updateRecents:[self dictionaryAtIndex:indexPath.row]];
You're creating a new RecentsTableViewController (it is not the same as the one in the tab bar), setting its "recent items", and then releasing it. Nothing else has a pointer to it, so nothing else will see its "recent" items.
There are at least three easy-ish ways to update the "recents" controller:
Access it directly from the tab bar controller (incredibly icky layering violation and breaks when you change the tab order or the navigation structure or...): [(RecentsTableViewController*)[self.tabBarController.viewControllers objectAtIndex:...]) updateRecentsWithDictionary:...]
Post a notification, which you listen for in RecentsTableViewController: [[NSNotificationCenter defaultCenter] postNotificationWithName:MyViewedPictureNotificationName object:nil userInfo:...]
Save it to NSUserDefaults. Load it from NSUserDefaults in -[RecentsTableViewController viewWillAppear:]. The advantage here is that it persists across app launches. (There is the implicit assumption that the defaults will not change while the "Recents" view is visible".)
I've got a weird problem with a TableViewController.
In the doc it says that a tableViewController deals also with the method
-flashScrollIndicators when the table is "oversized" respect the visible area.
My app consists in 3 nav controller loaded in a tab controller. Each nav controller has as root view controller a subclass of a table view controller.
Each "model" is populated from a plist file, that loads its contents into an array in the -viewDIdLoad, later everything is passed to the table. Everything is loaded programmatically no IB.
I've found out in my app that when it loads the first view (a nav controller with a table view controller as root) the scroll bar isn't flashing even if the number of cell it's great enough.
If I choose another tab, that loads another nav controller (with a t.v.c. as root) scroll bar isn't shown again. When I press the tab corresponding to the first nav controller loaded the scrollbar flashes.
So I've tried to make it flash programmatically but no way, the code seems simple:
[self.tableView flashScrollIndicators];
I've tried to put it almost everywhere. First in the -viewDidLoad (As suggested in the doc), then in viewDidAppear and in -viewWillAppear.
Also tried use that code tring to cast the view of the t.v.c. as a table view.
[((UITableView*)self.view) flashScrollIndicators];
..without result.
I've started looking at Apple sample and I've found that in Apple's table view custom sample (the one with different times) scroll bar doesn't flash also there.
Tested both on sim and device.
Is a bug?, is there a correct way to show it programmatically?
Can someone help me?
Regards,
Andrea
Or more concisely:
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self.tableView performSelector:#selector(flashScrollIndicators) withObject:nil afterDelay:0];
}
I had exactly the same problem. I got around it in the end by putting a delayed selector in the viewDidAppear: method. Weirdly, I can set it to 0 seconds and it still works fine.
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self performSelector:#selector(flashTableScrollIndicators) withObject:nil afterDelay:0.0];
}
- (void)flashTableScrollIndicators
{
[self.tableView flashScrollIndicators];
}
It is not displayed when you show section index titles.
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView;
My solution was to send the "flashScrollIndicators()" message with a slight delay using "dispatch_after":
let delayTime = dispatch_time(DISPATCH_TIME_NOW, Int64(0.4 * Double(NSEC_PER_SEC)))
dispatch_after(delayTime, dispatch_get_main_queue(),
{ () -> Void in
myScrollView.flashScrollIndicators()
})
I was able to manage rows(add, delete and reorder) of an uitableviewcell in navigation based application, but it is not working in a view based application. The edit button that created in navigation type application is making it possible to edit. Anyone knows what action method is called when the touch up inside of this navigation button occurs? What is happening on this method is that the provisions for adding, deleting and reordering rows coming up on this action, but i've not written any action method of this. SO is there any similar way in a view based application to do these things??
The UIViewController is having its setEditing:animated: method called by that nav bar button. If you're hooking up a regular button, your handler should call that method, and the method should look something like this:
- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
[super setEditing:editing animated:animated]; // must be called first according to Apple docs
[table setEditing:editing animated:animated];
}
i.e. your controller will tell the table to also go into editing mode.