normally, the way to update a tableView is calling self.tableView reloadData (or setNeedsDisplay), but my (visible) tableView doesn't reload by calling this method.
My context is, that I've got a Navigation-Bar and a TableView and by clicking a button on the Navigationbar, the method "aktualisieren" starts. This method also works (i use a UIAlertView to check it) But the Context just updates when i scroll the TableView (after reloading) in the unvisible area (top oder bottom). Then, just the cells which were in the outside area are reloaded. Why? Can anyone helps me?
Thank you very much,
Jonathan
It sounds like your IBOutlet might not be hooked up.
Check that you have an IBOutlet of type UITableView in your view controller and that its connected correctly to the table that you want to update in Interface Builder.
If you MyViewController.h file you should have
IBOutlet UITableView *myTableView;
#property(nonatomic, retain) UITableView *myTableView;
and in interface builder ctrl-drag from the FileOwner (MyViewController) to the table view you want to update and selected myTableView to link it.
One thing to check would be to make sure that self.tableView is hooked up to the actual table view.
I often forget to do this, and if this is the case, then the reloadData message is not reaching the table view.
Related
I am working on a simple UI, but am running into trouble with addSubview calls made after a removeFromSuperview.
In my viewController I have an IBOutlet UITableView
#property (strong, nonatomic) IBOutlet UITableView *tableView;
Depending on the state of the data, I remove the tableview from my viewControllers view.
[self.tableView removeFromSuperview];
So far so good, the view is removed. When using the debugger, I can still see that my viewController has a valid handle to the tableview. The problem starts on the next line when I call addSubview.
[self.view addSubview:self.tableView];
[self.tableView setDataSource:studyResult];
[self.tableView reloadData];
It seems to do nothing and I can't see any change in the UI. I have tried to set the frame on the tableView and still no results.
Have any of you seen this behavior?
Joe
Hi Joe can you give me more code for see what are you going? what I get, is that you have your control and a tableview view inside that you want to shot just when you have your array with the data? if is like that why you don't set Hide the tableview when you haven't the data? every time that you refresh the data for the table you have also to use the method reloadData for refresh the table
Depending on the state of the data, I remove the tableview from my viewControllers view.
Consider segueing to another view controller with a table view instead of swapping out table views in a single view controller. Or, if the new data is a subset of the old data, then leave the table view in place and filter its data.
I have this structure:
UIScrollView:
View
View:
UITableView
I have set all in a XIB file.
When I click in a row of the UITableView inside the limits of its view in the XIB file, it´s ok (it goes to didSelectRowAtIndexPath method). But if I scroll and then I click in a row of the UITableView beyond the limits of the view size in the XIB file, it does not go to didSelectRowAtIndexPath. What is happening and how should I correct it?
Thanks.
the scroll view delegate methods will get called when you scroll a table view...
i think the code written in side the scroll view delegate methods are creating the problem in your case...
check those methods once...
if it is like so to avoid the execution of code in the delegate methods write these lines
if([scrollView isKindOfClass:[UITableView class]])
return;
the main tableview will have rows that is added/created from the user and that row will open their own tableview which also have their own add/create own row. My main question is how to make sure each row thats added in the main tableview opens their own tableview (as blank until added from user).
This link i've seen is the closest How can I move to another view controller when the user clicks on a row? but not exactly what Im looking for. Most of the samples/tutor is all ususally populated or already have an array in their tableview. I wanted to make mines both completely nothing in it but added only by the users and main tableview each row opens its own tableview.
I already have two tableview one is main and other is sub to each row. I was able to insert row in main table view but it opens the same tableview as the other rows in the main tableview and would like to know how to make sure each row in main tableview opens their own blank tableview.
Usually your view controller controls the tableView. I guess you are trying to fit in there multiple table views and logic for each one. Instead, just create controllers for each table.
First create your main view controller using a UIViewController template (don't use a TableViewController). Use a XIB and add there a TableView element, OR create a UITableView instance using code.
Now create a class conforming to the delegate and datasource, protocols. This doesn't need to be a view controller. Example:
// MiniTVC.h
#interface MiniTVC : NSObject <UITableViewDelegate, UITableViewDataSource>
#property (nonatomic, retain) IBOutlet UITableView *tableView;
#property (nonatomic, retain) NSArray *array;
-(id) initWithTableView:(UITableView*)tableView array:(NSArray*)array;
#end
and implement the delegate and datasource methods as usual. You need at least the following:
tableView:heightForRowAtIndexPath:
numberOfSectionsInTableView:
tableView:numberOfRowsInSection:
tableView:cellForRowAtIndexPath:
Then back to your main view controller, you create (or hook from the interface designer using IBOutlets) a tableView and set its delegate and datasource to your MiniTVC class, eg:
// sample table created by code
CGRect frame = CGRectMake(50,50,100,100);
UITableView *tableView = [[UITableView alloc] initWithFrame:frame]
[self.view addSubView:tableView];
// set the datasource/delegate
MiniTVC *miniTVC = [[MiniTVC alloc] initWithTableView:self.tableView array:someArray];
tableView.dataSource = self.miniTVC;
tableView.delegate = self.miniTVC;
You can repeat this process creating another UITableView + MiniTVC from inside a custom UITableViewCell. Or you could make the UITableViewCell conform to the table delegate/datasource and implement there the methods.
Btw, creating tableviews inside tableviews is a bit unusual. Since they are both UIViewScroll subclasses, it could lead to unexpected behaviour, tho I haven't tried myself.
I'm using a UITableViewController and want to add a searchbar.
My options are [self.tableview addSubview:searchBar] or self.tableview.tableHeaderView = searchBar
Both options will scroll the searchbar along the rest of the tableview, which I understand. But is there a way to lock elements up, instead of using a UIViewController or changing the frame origin on scroll?
I'm thinking of a way to get above the current view hierarchy and add a subview onto that.
I tried the opposite approach, to add a view to the superview and bring that to front
[[self.tableView superview] addSubview:searchBar];
[[self.tableView superview] bringSubviewToFront:searchBar];
}
but it didn't work.
UITableViewControllers are UIViewControllers that have their main view property being an UITableView. Thus this UITableView do takes all the screen.
The approach you are looking for is to use a standard UIViewController whose view is a standard UIView, and add your UISearchBar and the UITableView as a subview to it in IB.
To do this, simply:
Change the class of your view controller and instead mention that it conforms to the tableview-associated protocols : change #interface UITableViewController to #interface UIViewController <UITableViewDelegate, UITableViewDataSource>
Add a #property(nonatomic, retain) IBOutlet UITableView* tableView property to your header file, and the associated #synthesize tableView; statement in the implementation. Don't forget to set this property back to nil (self.tableView = nil) in your dealloc for good memory managment
Link your UITableView instance in InterfaceBuilder to this newly created IBOutlet.
Thus you still have a UITableView but this won't be the main view that takes all your screen; instead you can layout your tableView like you want and make it take only a part of your screen, and position the UISearchBar above it.
Another approach would be to use the UISearchDisplayController to manage your UISearchBar.
How is a UIActivityIndicatorView added to a UITableViewController?
I have tried adding it in Interface Builder and when I drag and drop it onto the view, it just disappears.
I need to show the activityIndicator while the table loads in its data.
If you put a tableview (not a tableview controller) inside another view you can place the activity indicator on top of it. To clarify:
- Plain xib file with a Files Owner and a First Responder
- Add a View (not a view controller)
- Add a TableView into the View
- Add an Activity Indicator into the View
For some reason, the various view controller objects don't like you adding things to them and the tableview object doesn't like you adding things to it. I'm sure that the docs make this really clear somewhere.
You can add UIActivityIndicatorView to your tables in the Interface Builder (IB), but a recommended way would be:
User IB to create and customize a UITableViewCell. Put a UIActivityIndicatorView inside this cell.
Programmatically load your table cells with the customized UITableViewCell nib file.
Programmatically hook up IBOutlets of such UIActivityIndicatorView.