RCB
RCB

Reputation: 2263

Can I get an instance of a view by ID, like in Android?

I have a table view, which was added in Interface Builder. How can I get its instance in the view controller?

Is there a way like in Android by using getViewById()?

And if so where do I give the view its id?

Upvotes: 2

Views: 1755

Answers (2)

vishwa.deepak
vishwa.deepak

Reputation: 510

I think you are starter in iPhone sdk, the solution goes as follows:

  1. At first in the .h file of your view controller, add these lines, IBOutlet UITableview * myTableView;
  2. Now open the .Xib file of the same view controller and then link the TableView from the xib to the files owner, there the name of the TableView will appear.
  3. Also link the delegate and data sources of the Tableview.

Upvotes: 5

iPatel
iPatel

Reputation: 47049

Create and add UITableView programmatically and use it object (This is only for UITableView).

self.tblView            = [[UITableView alloc] init];
self.tblView.frame      = CGRectMake(0, 87, self.view.frame.size.width, 374);
self.tblView.delegate   = self;
self.tblView.dataSource = self;
[self.view addSubview:self.tblView];

Here self.tblView is object of UITableView you can use it as per your requirement.

Or get each object of subview of UIView

NSArray *subViewArray = [self.view subviews];
for (id obj in subViewArray)
{
  // here **`obj`** get each object of subView of UIView.
}

Upvotes: 0

Related Questions