1

Possible Duplicate:
Difference beetween _ and self. in Objective-C

Should I use self.tableView or just tableView by itself.

In my code I've noticed that both

[self.view addSubview:self.tableView];

and

[self.view addSubview:tableView];

both work. My tableView was added with IB and the delegate and datasource and outlet was set.

thanks

Community
  • 1
  • 1
hanumanDev
  • 6,592
  • 11
  • 82
  • 146
  • thai bhai thai avu mare pn 1 var thayu hatu :( –  Dec 13 '12 at 12:09
  • 1
    When you do self.tableView, behind the scenes what is happening is that [self getTableView] is being called. So though, 99% of the time, you get what you want, there are cases, where getProperty implmentation may do some thing additional as well. It is basically the difference between accessing a property and a variable. – Srikanth Dec 13 '12 at 12:10

2 Answers2

1

If you are declaring your table and not making its property like

IBOutlet UITableView *table;  

then you can access you tableView

[self.view addSubView:tableView];

And If you are setting its getter and setter property then you can call using self.table

@property(nonatomic,retain)IBOutlet UITableView *table;  

Then you can access it by

 [self.view addSubView:self.table];  

For more info you can read UITableViewController Class Reference

Rajneesh071
  • 30,846
  • 15
  • 61
  • 74
0

Just adding to the above answer

If your table is made a property then it is better to always use

[self.view addSubview:self.tableView];

One of the advantages of doing so is when synthesized as a property the accessors are generated for it whereas in the other method this does not happen. The retain and release will be done by the accessors if property was set to retain.

From personal experience I suggest you will be able to avoid memory access violations at least.

sujithra s
  • 41
  • 6