I am having trouble displaying data in my table.
Preamble:
TableView placed on the storyboard
TableView linked to a #property (strong, nonatomic) IBOutlet UITableView *myTable;
.m file contains both required methods and content to be displayed
Controller conforms to <UITableViewDataSource>
I suspect i am not setting up the dataSource in the right place. Where in a UIViewController should it be set, when initialization happens from the StoryBoard? I placed it in the -(void)viewWillAppear:(BOOL)animated, however DataSource was not set. Same goes for init.
[myTable setDataSource:self];
If the view is loaded with the help of storyboard (initialization does not happen as part of init method) .. where should table's dataSource be set?
The controller's -viewDidLoad method would be a good option. That method is meant to perform any initialization that has to be deferred until the view is loaded.
I'm not sure what you mean by 'did not take.' Is the table's data source not set to your controller?
Related
I have an NSTableview in class "spielplan", which I can reload easily with reloadData, but how can I reload the Table from my AppDelegate.m???
I think, there is a simple solution, but I don't get it!
Short answer: You shouldn't.
You class spielplan (which should be renamed to PMGameBoard) is probably a controller class that manages views, including the tableView. So it's the responsibility of this controller to reload the tableView's data should need be.
The external event from your app delegate, whatever it is, should be made available to the spielplan instance by some means of notification. The exact method of communication depends on the type of event (NSNotification, ...). See this objc.io article.
Create property or outlet (depends on do you use storyboard or not) in your spielplan.h file, for example
#property (nonatomic, strong) IBOutlets UITableView *myTableView;
and in the AppDelegate file get reference to spielplan object and call reload method:
[spielplan.myTableView reloadData];
If spielplan is subclass of UITableViewController you don't have to create outlet or property to the table view in your AppDelegate call:
[spielplan.tableView reloadData];
Bear in mind that when you try to get reference to your view controller from AppDelegate and the view controller is not in view hierarchy it can be deallocated or maybe it hasn't been allocate yet and call reloadData it doesn't make sense.
I have tried to use
self.myUITextView.text = #"hi";
to update my UITextView in my Nib file.
However, the original text of the UITextView is still on the screen. How do I update a UITextView in my view controller?
Give proper connection (IBOutLet) from xib to your view controller. You have missed the IBOutLet connection of UITextView from nib to controller as i guess.
I am sure you must have declared the UITextView as
IBOutlet UITextView *myUITextView;
and also properly connected it to your XIB.
Then declare the following property in your .h file
#property (nonatomic, retain) IBOutlet UITextView *myUITextView;
and synthesize it in your .m file
#synthesize myUITextView;
Now try to change the text to whatever you want. In your case
myUITextView.text = #"hi";
You can use the set property of uitextview [self.myUITextView setText:#"Hi Updated"];
in -(Void)viewWillApper method.
Make sure your UITextView IBOutlet in IB is hooked up with a valid connection to your controller's property.
Wait until "viewDidLoad" is called to change the text (before that, you have no guarantee the text view is loaded in memory).
Change the text property (as you did).
You are doing wrong thing....You are specifying value in load method...So even though you have changed the value, when you try to load that view again...viewDidload method will be called and the new value will be replaced by the original value....
Instead of setting value in viewDidload..Make some method or put some button ang in its click method,Set the value and store it somewhere......You are doing totally wrong thing.
I'm building a Core Data document based application. In the app there's a main view (NSTableView) and an inspector view. Both views are separate nib files. The content of the inspector view should depend on the selected row in the main view. I have three controller files:
DocumentWindowController (master controller)
ItemsViewController (main view)
SchedulesViewController (part of the inspector)
Every controller owns a nib file. How is it possible to change the content of the inspector when the user selects another row in the main view's table?
I tried to make it work as follows:
Every controller has it's own NSArrayController, which is set up in the DocumentWindowController. The DocumentWindowController gets its managedObjectContext from [[self document] managedObjectContext]
When a user clicks a row in the ItemsViewController's tableView, an NSNotification is posted, with [NSTableView selectedRow] as a parameter. Then a fetch request is being made.
My intuition says I have to do this with Cocoa bindings.
I searched on Stackoverflow and google but I just can't make it work. If everything is in one nib file is very easy to accomplish. What is the best/most used way to achieve this?
Thanks in advance!
You could follow the same paradigm as the table view and create a data source for your inspector view.
#protocol InspectorDataSource <NSObject>
- (void) inspectorView:(InspectorView*)inspectorView managedObjectSelected:(NSManagedObject*)managedObject;
#end
Your inspector view controller would then have the data source as a property.
#interface InspectorViewController : UIViewController{
#public
id<InspectorDataSource> dataSource;
}
#property (nonatomic, assign) id<InspectorDataSource> dataSource;
Can anyone describe how it is possible to have a TableViewController with its xib file having a at its root and the uitableview as a subview?
I believe the TVController somehow assumes that UITableView will fill the entire area.
Why is that?
I have a really specific need to build a kind of side and bottom tabbed interface with a UITableView as its main area. Pressing tabs changes the predicate for the fetchedresultscontroller etc etc.
The reason I want this is because of the breadth and depth of the data categories in the data model. I rally need to flatten the menu structure a lot...other wise with a table and navbar controller structure, user experience will be akin to sinking to ever deeper depths of a cavern!
My idea is tried and true in other paradigms...in iOS it almost looks like it's Apple's way or the highway. I am OK with APPLE of course no gripe.
But I really would like to create this.
I tried adding a new tableviewcontroller complete with xib and then removing the UITableView in IB and replacing with a UIView and a UITableView as a subview, hooking up (I believe) the delegate to the file's owner.
I created an IV tableView for when I want to reference it and again used IB to hook it up in IB
Try to run it and it whines that...
[UITableViewController loadView] loaded the "TabbedTableController" nib but didn't get a UITableView.'
Really can't seem to get my head around what the issue is here.
There doesn't appear to be anymore I can do to hook the UITableView up!
Any help would be terrific. I'll send you a Christmas card in desperation :^)
Also...why should it be so and how strict is this UITableView fullscreen thing?
Enlighten me if you can. The docs I have read don't want to.
Regards
Keith
A UITableViewController does assume that the root view (i.e. the controller's view property) will be a UITableView, thus the table view fills the screen. When you need a view that combines UITableView with other top level views, you will need to do a little more work but it's not hard:
Your view controller will not subclass UITableView. Instead, do this:
#interface MyViewController : UIViewController
<UITableViewDelegate, UITableViewDataSource>
#property (nonatomic, weak) IBOutlet UITableView* tableView;
In Interface Builder, drop in a UITableView and whatever other controls you need. The table view can be any size and in any location in the view hierarchy. Also in Interface Builder, ctrl-drag from the table view to your VC and set the delegate and dataSource outlets, and ctrl-drag from your VC to the table view to set the tableView outlet.
Your view controller implementation should be the typical table view controller implementation: cellForRowAtIndexPath, etc.
A UITableViewController is more or less just all of the above work packaged up into a single unit for you.
Let's say I have a ViewController that needs access to a view. In the class file of the ViewController I am doing
IBOutlet ViewA *someview;
And in Interface Builder, I drag and drop a UIView in my document and set the class to ViewA.
I am missing how "stuff" is instantiated when you connect through IB. Is ViewA automatically allocated when the .xib files are unarchived? What if I don't want to use IB?
If you don't want to use IB, instead of putting that IBOutlet there, you just eliminate it, leaving just
ViewA *someview;
and then somewhere in your code, when you need the view, you do a
someView = [[UIView alloc] initWithFrame: rect];
I prefer IB, others prefer programmatically creating views. I like how I can position all the views subViews, including UIButtons, UILabels, UITableViews, other UIViews, etc. without having to use coordinates to do so. YMMV.
As to when things get instantiated, when using a XIB, your app will probably lazily load the view controller, and once it is loaded, it will load your view. What actually loads your view, is when you first access the variable someView. While there is an outlet connection, the view and its subViews are not loaded till you access someView, in any manner, for example if you just do a:
if (someview) {
// the view is loaded now
}