UITableView within a UIViewController - Data doesn't load - objective-c

I know that there are several posts around the www, but sadly I don't get the tableView to be loaded.
here is my code:
.h file
#interface ViewControllerSzenenLichter : UIViewController<UITableViewDelegate, UITableViewDataSource>{
IBOutlet UITableView *tableView;
}
#property (nonatomic, retain) IBOutlet UITableView *tableView;
#end
I connected the IBOutlet with my tableview in the Storyboard
.m file
#interface ViewControllerSzenenLichter ()
#end
#implementation ViewControllerSzenenLichter
#synthesize tableView;
somewhere in the code I try to execute
[self.tableView reloadData]
which is executed(checked by Breakpoint)
but the method numberOfRowsInSection or numberOfSectionsInTableView are never called!
As mentioned I found a lot of tutorials in the web, but I can't solve the Problem.
thanks

Your child tableView is basically a cell of your parent tableView.
So, unless you reload your parent tableView, the cell will not update, and hence, the child tableView will not be plotted.
[childTableView reloadData];
[parentTableView reloadData];
EDIT :
And #Desdenova is right. Make sure you set your delegate and data source to self or whatever class manages the tables.

In the storyboard Right click over the table you will see datasource and delegates as the first two options.Connect both to the viewcontroller (same as you did for outlet connection) and run again.
The final table connections will be like this

It seems, you connect one IBOutlet and use another when reload data: You have two ivars tableView (you create it manualy) and _tableView (created compiler and links with #property (nonatomic, retain) IBOutlet UITableView *tableView;), I don't now which one will be shown as TableView property of file owner in InterfaceBuilder. Try remove IBOutlet UITableView *tableView; ivar and reconnect Table in IB

First of all, make sure you are setting delegate in xib file or implementation file for your table. If still not working, check the code where you are reloading table. If main thread is busy doing something else, it will not call any of the delegate method of UITableView. So when the code finishes, then reload tableview.

Connect your TableView to the File's Owner by the delegate and datasource...
I think your problem will be solved. Here is a picture for your batter understanding...

Related

IBOutlet in ARC releases and sets to nil. How to avoid this? objective c

I'm new to ARC and Storyboarding. I've set IBOutlet to UITableView from my UIViewController.
After some time my IBOutlet sets to nil and I can't reload it from other classes.
Here is my dataTable IBOutlet:
#property (weak, nonatomic) IBOutlet UITableView *dataTable;
At the start dataTable is not nil, but not when I try to access it from another class (via appDelegate). How to solve this problem?
UPDATE
I call this method from my UIViewController
[appDelegate.myClass loginWithUserName:loginField.text andPassword:pwdField.text];
When it's done, and I have data to show, I call this code from loginWithUserName method:
MyViewController *controller = [[AppDelegate sharedStoryboard] instantiateViewControllerWithIdentifier:#"MyViewController"];
[controller audioLoaded];
And here is that method in my UIViewController, wich reloads data
-(void) audioLoaded
{
//it is nil here
[self.dataTable reloadData];
}
Set the property to strong retain the object:
#property (strong, nonatomic) IBOutlet UITableView *dataTable;
It's not good practice to access a UITableView from another view controller though..
EDIT:
You shoul reconsider the whole approach, by moving that logic from your appdelegate to a dedicated class that will perform the login. You can create a simple protocol that the UIViewController with the table can implement, then, when calling the login method, pass a reference to the current viewcontroller, something like
loginWithUserName:andPassword:andCaller:(id<LoginDelegate>)sender
Where LoginDelegate is something on this line:
#protocol LoginDelegate
- (void)audioLoaded;
#end
In this way you can just call
[sender audioLoaded];

Reloading a TableView's data?

I'm trying to build a hello world application with Xcode 4.3.
So far, I have a TableView (dragged and dropped from the objects list) and a TableViewCell (also dragged and dropped from the objects list).
I have an array too, and my TableView works and gets the data from array, but how can I reload the TableView's data? I tried [self.tableView reloadData]; but it doesn't work. When I type [self., tableView is not in my options...
To have the NSTableView as a property of your class, you have to declare it as one.
In the interface of your class add:
#property (weak) IBOutlet NSTableView *tableView;
In the implementation add:
#synthesize tableView;
Then in Interface Builder connect the table view to the tableView outlet of your class, by right clicking on "File's Owner" and dragging a line from "tableView" to your table view.

Can't link datasource of two tablesView

So I have two TableView in one view of an iOS app. I have connected the delegate of both tableViews to the ViewController, and the app works. The problem is when I connect to the viewController the dataSource, so when I run the app Xcode returns to me a SIGABRT.
Anyonoe knows what am I doing wrong?
Make sure that the tableViews are not pointing to delegates that don't exist anymore. For example you might have deleted a delegate from your code but forgot to delete the connection from the tableview to the delegate.
Can you post your code?
#interface ViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
{
}
#property (weak, nonatomic) IBOutlet UITableView *Listview;

Modifying properties of a view controller form another view controller

In my project, there are two view controllers - let's say firstViewController and secondViewController. The second view controller has a button, and I want to make sure when the button gets pressed, the second view controller is telling somehow the first view controller - "hey, I got pressed, do something!", and it will do something, like changing a label. How is this possible to perform? Thanks in advance. Some code :
#interface firstViewController : UIViewController
#property (weak, nonatomic) IBOutlet UILabel *textLabel;
#end
#implementation firstViewController
#synthesize textLabel;
#end
#interface secondViewController : UIViewController
-(IBAction)buttonPressed;
#end
#implementation secondViewController : UIViewController
-(IBAction)buttonPressed{
// Hey, I got pressed! Set the text on textLabel to "OK"!
}
#end
This is a very simple case of delegation and protocol mechanism of objective-c..
have a look at this tutorial which will explain you how its done.. you can do this via notification also but that is not usually advised...(because notification is usually used when the receiver is unknown , like in the case of UIDeviceBatteryLevelDidChangeNotification you don't exactly know which view controller wants to know about this.)
I'd first consider what the button press means. Does it change the state of the model?
Say your model is an int, and the button increments it. The view controllers wouldn't message each other about that, they would just both observe the state of the model. (The one with the button could change the state, too).
Thinking about it this way, the solution probably isn't delegation. It's probably notification or KVO.
See the answer to this question: Passing data between two view controllers via a protocol
However, ask yourself if you really need a protocol here. If it is just between this classes or just about the question of accessing data of a class or sending information to a class then that is what the interface of a class is made for.
#interface firstViewController : UIViewController{
UILabel *textLabel; // I personally alway add IBOutlet here too, but I think that is not required.
}
#property (weak, nonatomic) IBOutlet UILabel *textLabel;
#end
And in SecondViewController.m:
#import "FirstViewController.h"
#implementation secondViewController : UIViewController
-(IBAction)buttonPressed{
// You will have to have a properly set instance variable firstViewController
[firstViewController.textLabel setText:#"OK"];
}
#end
So your second view controller needs to 'know' the first one. One way of achieving that is defining
FirstViewController *firstViewController;
as property and set it from wherever the second view controller is created and the first one is already known. How to do that exactly depends very much on the architecture of your app.

Why can I not wire up my IBOutlets in storyboard?

I have a ViewController that has a couple of IBOutlet properties defined for UITextView. In the storyboard I have assigned my viewcontroller to the custom view controller. When I cntr + click on the viewcontroller I can see my two IBOutlets. When I try to drag them to the UITextViews on the storyboard they will not highlight and cannot be assigned.
I'm new to xcode 4.
Here is the property definitions from the viewcontroller:
#interface CreateUserViewController : UIViewController<UITextInputDelegate>
#property(nonatomic,retain) KeychainItemWrapper *keyChainWrapper;
#property(nonatomic,retain) IBOutlet UITextView *userNameTxt;
#property(nonatomic,retain) IBOutlet UITextView *passwordTxt;
These properties are synthesized in the implementation. I can assign each of the textfields' delegate to the viewcontroller without a problem. Am I missing any step?
Thanks
Make sure that the views you're trying to connect really are UITextViews and not UITextFields. It's not difficult to get them mixed up.